Pop Manual
Pop Manual
Pop Manual
Approved by
HOD(CSE)
Question 1
Simple Calculator
C Code
/***************************************************************************
*File : A01Calculator.c
*Description : Program to simulate a commercial calculator
*Date : 10 August 2023
***************************************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int iChoice, iOperand1, iOperand2;
char cOperator;
for(;;)
{
printf("\nEnter the arithmetic expression(Do not add spaces in
the expression)\n");
scanf("%d%c%d", &iOperand1, &cOperator, &iOperand2);
switch(cOperator)
{
case '+': printf("\nResult = %d", iOperand1 + iOperand2);
break;
Output
C Code
/***************************************************************************
*File : A02Quadratic.c
*Description : Program to find the roots of a Quadratic Equation
*Date : 10 August 2023
***************************************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void)
{
float fA,fB,fC,fDesc,fX1,fX2,fRealp,fImagp;
int iState;
printf("\n*************************************************************");
printf("\n*\tPROGRAM TO FIND ROOTS OF A QUADRATIC EQUATION\t *\n");
printf("*************************************************************");
Output
Electricity Bill
An electricity board charges the following rates for the use of electricity: for
the first 200 units 80 paise per unit: for the next 100 units 90 paise per unit:
beyond 300 units Rs 1 per unit. All users are charged a minimum of Rs. 100 as
meter charge. If the total amount is more than Rs 400, then an additional
surcharge of 15% of total amount is charged. Write a program to read the
name of the user, number of units consumed and print out the charges.
C Code
/***************************************************************************
*File : A03ElectricBill.c
*Description : Program to perform a binary search on 1D Array
*Date : 10 August 2023
***************************************************************************/
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
char cName[30];
int iUnits;
const int iMinCharge = 100;
const double dSlab1 = 0.8;
const double dSlab2 = 0.9;
const double dSlab3 = 1.0;
const double dSurcharge = 0.15;
double dBillAmount = 0.0;
Output
/***************************************
Enter the name of the customer : Ramesh
Enter the number of units consumed : 457
Electricity Bill
===================================
Customer Name : Ramesh
Units Consumed 457
Bill Amount : 583.05 Rupees
Electricity Bill
===================================
Customer Name : Jaswinder
Units Consumed 300
Bill Amount : 350.00 Rupees
Electricity Bill
===================================
Customer Name : Shyam
Units Consumed 182
Bill Amount : 245.60 Rupees
*********
===================================
Printing Pattern
C Code
/***************************************************************************
*File : A04Pattern.c
*Description : Program to print a Pattern
*Date : 10 August 2023
***************************************************************************/
#include<stdio.h>
#include<stdlib.h>
int main()
{
int iNum, iSp_cnt, iNum_cnt, iVal, i, j, k;
printf("Enter the number of rows : ");
scanf("%d", &iNum);
iSp_cnt = iNum - 1;
iNum_cnt = 1;
for(i=0;i<iNum;i++)
{
iVal = 1;
for(j=0;j<iSp_cnt;j++)
{
printf(" ");
}
for(k=0;k<iNum_cnt;k++)
{
if(k <= iNum_cnt/2)
{
printf("%d ", iVal);
iVal++;
}
Output
/****************************
Binary Search
C Code
/***************************************************************************
*File : A05BinarySearchIntegers.c
*Description : Program to perform a binary search on 1D Array of Integers
*Date : 10 August 2023
***************************************************************************/
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int iaArr[100],iNum,i,iMid,iLow,iHigh,iFound,iKey;
iFound = 0;
iLow = 0;
iHigh = iNum-1;
while(iLow <= iHigh)
{
iMid = (iLow+iHigh)/2;
if(iKey == iaArr[iMid])
if(iFound)
printf("\nKey element %d found at position %d\n",iKey,iMid+1);
else
printf("\nKey element not found\n");
return 0;
}
Output
/****************************
Enter the number of elements
5
***************************************/
Matrix Multiplication
C Code
/***************************************************************************
*File : A06MatrixMul.c
*Description : Program to implement Matrix Multiplication
*Date : 10 August 2023
***************************************************************************/
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int iM, iN, iP, iQ, i, j, k, iaMat1[10][10], iaMat2[10][10];
int iaProd[10][10] = {0};
printf("\n*********************************************************");
printf("\n*\tPROGRAM TO IMPLEMENT MATRIX MULIPLICATION\t*\n");
printf("*********************************************************");
if( iN != iP)
{
printf("\nMatrix Multiplication not possible\n");
exit(0);
}
printf("\nEnter the elements of Matrix 1\n");
for(i=0;i<iM;i++)
for(i=0;i<iM;i++)
{
for(j=0;j<iQ;j++)
{
for(k=0;k<iN;k++)
{
iaProd[i][j] += iaMat1[i][k] * iaMat2[k][j];
}
}
}
printf("\nMatrix 1\n");
for(i=0;i<iM;i++)
{
for(j=0;j<iN;j++)
{
printf("%d\t",iaMat1[i][j]);
}
printf("\n");
}
printf("\n");
printf("\nMatrix 2\n");
for(i=0;i<iP;i++)
{
for(j=0;j<iQ;j++)
{
printf("%d\t",iaMat2[i][j]);
}
printf("\n");
for(i=0;i<iM;i++)
{
for(j=0;j<iQ;j++)
{
printf("%d\t",iaProd[i][j]);
}
printf("\n");
}
printf("\n");
return 0;
}
Output
*********************************************************
* PROGRAM TO IMPLEMENT MATRIX MULIPLICATION *
*********************************************************
Enter the order of Matrix1
23
Enter the order of Matrix2
32
Matrix 1
1 2 3
4 5 6
Matrix 2
1 2
3 4
5 6
C Code
/***************************************************************************
*File : A07SineCosAngle.c
*Description : Program to calculate Sin(x)/Cos(x) using Taylor series
*Date : 10 August 2023
***************************************************************************/
#include<stdio.h>
#include<stdlib.h>
#include <math.h>
int main()
{
float fAngD, fAngR;
float fTerm, fNum, fDen, fSVal,fCVal;
int i,iNum;
printf("\nEnter the Angle : ");
scanf("%f",&fAngD);
printf("\nEnter the Number of terms : ");
scanf("%d",&iNum);
printf("\nInput Angle = %g\n",fAngD);
printf("No of terms = %d\n",iNum);
fAngR= (fAngD*M_PI)/180 ;
return 0;
}
Output
/***************************************
C Code
/***************************************************************************
*File : A08BubbleSort.c
*Description : Program to implement Bubble Sort Algorithm
*Date : 10 August 2023
***************************************************************************/
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int iNum, i, j, iaArr[10], iTemp;
printf("\n*************************************************");
printf("\n*\tPROGRAM TO IMPLEMENT BUBBLE SORT\t*\n");
printf("*************************************************");
printf("\nEnter no of elements\n");
scanf("%d",&iNum);
for(i=0;i<iNum;i++)
{
for(j=0;j<iNum-i-1;j++)
{
if(iaArr[j] > iaArr[j+1])
}
}
printf("\nThe Sorted array is \n");
for(i=0;i<iNum;i++)
printf("%d\t",iaArr[i]);
printf("\n");
return 0;
}
Output
/***************************************
*************************************************
* PROGRAM TO IMPLEMENT BUBBLE SORT *
*************************************************
Enter no of elements
5
Enter the elements
21657
The Sorted array is
1 2 5 6 7
*************************************************
* PROGRAM TO IMPLEMENT BUBBLE SORT *
*************************************************
Enter no of elements
6
Enter the elements
975310
The Sorted array is
0 1 3 5 7 9
String Operations
C Code
/***************************************************************************
*File : A09StringFunctions.c
*Description : Program to implement string operations as functions
*Date : 10 August 2023
***************************************************************************/
#include<stdio.h>
#include<stdlib.h>
int main()
{
int iChoice;
char acStr1[30], acStr2[30];
int iLen;
printf("\n=====================\n");
printf("STRING OPERATIONS");
printf("\n=====================\n");
for(;;)
{
printf("\nEnter two strings\n");
printf("\nString 1 : ");
scanf("%s", acStr1);
printf("\nString 2 : ");
scanf("%s", acStr2);
printf("\n1.String Compare\n2.String Concatenate\n3.String Length");
printf("\nEnter your choice : ");
}
printf("\nPress 1 to continue and 0 to quit : ");
scanf("%d", &iChoice);
if(0==iChoice)
{
break;
}
}
return 0;
}
Output
/***************************************
=====================
STRING OPERATIONS
=====================
String 1 : shiva
String 2 : shankar
Concatenated String is
shivashankar
Press 1 to continue and 0 to quit : 1
String 1 : ramesh
String 2 : sumesh
1.String Compare
2.String Concatenate
3.String Length
Enter your choice : 1
String 2 : samantha
1.String Compare
2.String Concatenate
3.String Length
Enter your choice : 3
C Structures
Implement structures to read, write and compute average- marks and the
students scoring above and below the average marks for a class of N
students.
C Code
/***************************************************************************
*File : A10StudentStructure.c
*Description : Program to implement structure and compute average marks
*Date : 10 August 2023
***************************************************************************/
#include<stdio.h>
#include<stdlib.h>
#define STRSIZE 30
typedef struct
{
char cName[STRSIZE];
char cUSN[11];
int iMarks;
}STUDENT_TYPE;
int main(void)
{
STUDENT_TYPE students[100];
int iNum, i;
double dAvg = 0.0;
dAvg /= iNum;
for(i=0;i<iNum;i++)
{
printf("\n###############################");
printf("\nName\t: %s", students[i].cName);
printf("\nUSN\t: %s", students[i].cUSN);
printf("\nMarks\t: %d", students[i].iMarks);
if(students[i].iMarks < dAvg)
printf("\nThe student has scored below average\n");
else
printf("\nThe student has scored above average\n");
}
return 0;
}
Output
/***************************************
Enter the number of students : 4
Enter the Student details
=========================================
Name : Raju
USN : 1SI17CS036
Marks : 67
=========================================
Name : Michael
USN : 1SI17CS045
Marks : 87
=========================================
Name : Raju
USN : 1SI17CS036
Marks : 67
The student has scored below average
=========================================
Name : Michael
USN : 1SI17CS045
Marks : 87
The student has scored above average
=========================================
Name : Sahana
USN : 1SI17CS405
Marks : 77
The student has scored below average
=========================================
Name : Jonathan
USN : 1SI17CS025
Marks : 83
The student has scored above average
***************************************/
Develop a program using pointers to compute the sum, mean and standard
deviation of all elements stored in an array of N real numbers.
C Code
/***************************************************************************
*File : A11MeanVarianceSD.c
*Description : Program to compute Mean, Variance and Standard Deviation
using pointer to an array
*Date : 10 August 2023
***************************************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void)
{
int i,iNum;
float fMean = 0.0f, fVariance = 0.0f, fSd = 0.0f,faArray[100],fSum=0.0f;
float *fptr;
printf("\n**************************************\n");
printf("\tSum\t = \t%g\n\tMean\t = \t%g\n\tVariance = \t%g\nStandard Deviation =
\t%g",fSum,fMean,fVariance,fSd);
printf("\n**************************************\n");
return 0;
}
Output
/***************************************
Enter the number of Values : 4
Enter 4 values
1.1 2.2 3.3 4.4
**************************************
Sum = 11
Mean = 2.75
Variance = 1.5125
Standard Deviation = 1.22984
**************************************
============================================================
Enter the number of Values : 5
Enter 5 values
5.345 6.765 7.234 8.675 9.765
**************************************
Sum = 37.784
Mean = 7.5568
Variance = 2.34995
Standard Deviation = 1.53295
File Copy
Write a C program to copy a text file to another, read both the input file
name and target file name.
C Code
/***************************************************************************
*File : A12FileCopy.c
*Description : Program to copy a text file to another
*Date : 10 AUGUST 2023
***************************************************************************/
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
FILE *fp1,*fp2;
int ch;
char fname1[100], fname2[100];
printf("\nEnter File name to be copied\n");
scanf("%s",fname1);
fp1 = fopen(fname1,"r");
if(fp1 == NULL)
{
printf("\nInput File %s doesn't exist\n", fname1);
exit(0);
}
fp2 = fopen(fname2,"w");
while((ch=fgetc(fp1)) != EOF)
{
fputc(ch,fp2);
}
Output
/**************************************************
Enter File name to be copied
out9.c
===============================================
**************************************************/