KEMBAR78
548bc030-9f16-437e-8369-4e4d51dea007 | PDF | Software Engineering | Computing
0% found this document useful (0 votes)
7 views24 pages

548bc030-9f16-437e-8369-4e4d51dea007

The document outlines several programming tasks for a Computer Science and Engineering course, including creating a commercial calculator, computing roots of quadratic equations, calculating electricity charges, printing a specific pattern, and implementing binary search on a 1D array. Each task includes sample code snippets and expected outputs. The document serves as a practical guide for students to apply their programming skills in C.

Uploaded by

vardhimasihaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views24 pages

548bc030-9f16-437e-8369-4e4d51dea007

The document outlines several programming tasks for a Computer Science and Engineering course, including creating a commercial calculator, computing roots of quadratic equations, calculating electricity charges, printing a specific pattern, and implementing binary search on a 1D array. Each task includes sample code snippets and expected outputs. The document serves as a practical guide for students to apply their programming skills in C.

Uploaded by

vardhimasihaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y

H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

1. Simple computational problems using arithmetic expressions and


use of
Each operator leading to implementation of a Commercial calculator.

#i ncl ude <stdio.h>


#i ncl ude <conio.h>
int main()
{
int ch,a,b,re sult;
clrscr();
printf(“ Commercial C alculator\n” ) ;
printf("Enter two inte ge rs \n");
printf(“ Pe rforms the following Ope rations\n” );
printf(“ 1.Addition\n” );
printf(“ 2.Subtraction\n” );
printf(“ 3.Multi plicati on\n” );
printf(“ 4.Modular Divis ion\n” );
printf(“ 5.Divis ion\n” );
printf(“ Ente r your choi ce \n” ) ;
scanf(“ %d” ,&ch) ;
swi tch(ch)
{
Case 1:p rintf(“ Ente r Two Numbers to Add\n” ) ;
scanf("%d%d",&a,&b) ;
re sult=a +b;
printf(“ The Addition of number %d & %d is:%d\n”
,a,b,resul t);
break;
cas e 2:printf(“ Ente r Two Numbe rs to Subtract\n” );
scanf("%d%d",&a,&b) ;
re sult=a-b;
printf(“ The Subtracti on of number %d & %d is:%d\n”
,a,b,resul t);
break;
cas e 3:pri ntf(“ Enter T wo N umbers to Multip lay \n” );
scanf("%d%d",&a,&b) ;
re sult=a*b;
printf(“ The Multipli cation of number %d & %d is:%d\n”
,a,b,resul t);
break;

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

cas e 4:printf(“ Ente r Two Numbe rs to Modul ar


Di vi sion\n” );
scanf("%d%d",&a,&b) ;
re sult=a%b;
printf(“ The Modular D ivisi on of %d & %d is:%d\n”
,a,b,resul t);
break;
cas e 5:pri ntf(“ Enter T wo N umbers for Divis ion\n” );
scanf("%d%d",&a,&b) ;
if(b<=0)
printf(“ Error Divide B y Zero\n” ) ;
}
el se
{
re sult=a/b;
printf(“ The Divis ion of %d & %d is :%d\n” ,a,b,re sult);

}
break;
default: pri ntf(“ I nvalid Choice\n” );
break;
}
ge tch() ;
re turn 0;
}

Output:
1. Ente r Two Numbers to Add: 10 20
The Addition of number 10 & 20 is : 30
2. Ente r Two Numbers to Subtract: 20 10
The Subtraction of number 20 & 10 is : 10
3. Ente r Two Numbers to Multiply : 1 0 20
The Multipl ication of number 10 & 20 is : 200
4. Ente r Two Numbers to Add: 10 20
The Modular Divis ion of number 1 0 & 20 is : 0.50000
5. Ente r Two Numbers to Add: 20 1 0
The Addition of number 20 & 10 is : 2.0000

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

2. Develop a program to compute the roots of a quadratic equation by


accepting the
coefficients. Print appropriate messages.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c;
float root1, root2, real, img, disc;
clrscr();
printf("Enter the value of coefficient quadratic equation\n");
scanf("%f%f%f",&a,&b,&c);
if(a==0||b==0||c==0)
{
printf("The value entered for one of the co-efficent is zero\n");

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

getch();
exit(0);
}
else
{
disc = ((b*b)-(4*a*c));
printf("The value of the discriminant=%f\n",disc);
if(disc == 0)
{
printf(" The roots are real and equal\n");
root1=-b/(2.0*a);
root2=root1;
printf("Root1 = %f", root1);
printf("Root2 = %f", root2);
}
else if(disc>0)
{
printf("The roots are real and distinct\n");
root1=(-b+sqrt(disc))/(2.0*a);
root2=(-b-sqrt(disc))/(2.0*a);
printf("Root1=%f",root1);
printf("\nRoot2=%f",root2);
}
else
{
printf("The roots are complex and imaginary\n");
real=-b/(2*a);
img=(sqrt(abs(disc)))/(2*a);
printf("Root1=%f+i%f\n",real,img);
printf("Root2=%f+i%f\n",real,img);
}
}
getch();
return 0;
}

Sample Output 1:

Enter the three co-efficient:


144
The roots are real and equal
The roots are:

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

X1=X2=2.0000

Sample Output 2:
Enter the three co-efficient:
1-56
The roots are real and distinct
The roots are:
X1=3.0000
X2=2.0000

Sample Output 3:
Enter the three co-efficient:
234
The roots are real and imaginary the roots are:
1) -0.750000 +i 1.198958
2) -0.750000 - i 1.198958

Sample Output 4:
Enter the three co-efficient:
1 0 5 Invalid Input

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

3. 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.

#i ncl ude <s tdio.h>


#i ncl ude <conio.h>
#i ncl ude <s tring.h>
void main()
{
int unit;
float charge ;
char name [20];
clrscr();
printf("Enter the name of the cus tome r:\n");
scanf("%s ",&name );
printf("ente r the no.of.units consumed:\n");
scanf("%d",&unit);
if(uni t<=200)
{
charg e=1 00+unit*0.8;
}
el se if(uni t<=300)
{
charg e=1 00+(200*0.8)+((unit-200)*(0.9));
}
el se
{
charg e=1 00+(200*0.8)+((100*0.9)+(unit-300)) ;
}
if(charge >400)
{
charg e=charge+(charg e*0.15) ;
}
printf("**************************************************\n");
printf("CUSTUMER NA ME NO O F UN ITS
CO NSUMED\tC HARGES\n");

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

printf("**************************************************\n");
printf("%s \t \t\t%d\tRs .%0.2f\n",name ,uni t,charg e);
printf("**************************************************\n");
ge tch() ;
re turn 0;
}

Output:

Ente r the name of the customer:


Si ddarama
Ente r the no.of.units cons umed:
70
********************************************************
CUST UMER NAME NO O F UN ITSCON SUMED CH ARGED
********************************************************
Si ddarama 70
Rs .1 56.00
********************************************************

Ente r the name of the customer:


Naveenkumar
Ente r the no.of.units cons umed:
100
********************************************************
CUST UMER NAME NO O F UN ITSCON SUMED CH ARGED
********************************************************
Naveenkumar 100 Rs .1 80.00
********************************************************

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

4. Wri te a c p rogram to pri nt bel ow pattern by readi ng


numbe r of rows as inp ut.

1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
---------------------------------------------------------
n t h row.

#i ncl ude <s tdio.h>


#i ncl ude <conio.h>
#i ncl due <math.h>

int main()

int n;

int i ,j,k;

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

printf(“ Ente r the number of rows :\n” );

scanf(“ %d” ,&n);

for(i=1; i<=n;i++)

for(j=n=n-1;j>=I ;j--)

printf(“ ” );

for(k=i -1; k>=-(i-1); k--)

printf(“ %d” ,i-abs(k));

printf(“ \n” ) ;

re turn 0;

Output :

Ente r the numbe r of rows: 3

1
1 2 1
1 2 3 2 1

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

5. Introduce 1D Array manipulation and implement Binary search.


#i ncl ude <s tdio.h>
#i ncl ude <conio.h>
#i ncl ude <s tring.h>

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

void main()
{
int a[20],key,n,i,low,hi gh,mid,found=0;
clrscr();
printf("Enter the number of ele ments\n");
scanf("%d",&n);
printf("Enter the array i n ascending order\n");
for(i=0;i <n;i++)
{
scanf("%d",&a[i ]) ;
}
printf("Enter the key ele ment to be se arched\n");
scanf("%d",&key );
low=0;
hi gh=n-1;
whi le(low<=hi gh)
{
mid=(low+high)/2;
if(key ==a[mid])
{
found=1;
break;
}
el se if(ke y<a[mi d])
low=mid+1;
el se
hi gh=mid-1;
}
if(found==1 )
printf("Key el ement %d is found at
pos iti on: %d",key,mid+1);
el se
printf("Key e leme nt %d not found!\n",ke y);
ge tch() ;
re turn 0;
}

Output:
Ente r the numbe r of e leme nts: 5
Ente r the array in as cending orde r: 1 2 3 4 5
Ente r the key el ement to be searched: 3
Ke y ele ment 3 is found at p os ition:3

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

Output:
Ente r the numbe r of e leme nts: 5
Ente r the array in as cending orde r: 1 2 3 4 5
Ente r the key el ement to be searched: 0
Ke y ele ment 0 is not found.

6. Develop a program to introduce 2D Array manipulation and


implement Matrix multiplication and ensure the rules of
multiplication are checked.

/*the product of two matrix*/


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{

int i,j,k,m,n,p,q,a[10][10],b[10][10],c[10][10];
clrscr();
printf("Enter the order of the matrix A\n");
scanf("%d%d",&m,&n);
printf("Enter the order of the matrix b\n");
scanf("%d%d",&p,&q);
if(n==p)
{
printf("Enter the elements of the matrix A\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d", &a[i][j]);
}
}
printf("Enter the elements of the matrix B\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("Enter the elements of the matrix A are: \n");

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("Enter the elements of the matrix B are: \n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
printf("%d\t",b[i][j]);
}

printf("\n");
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
c[i][j]=0;
for(k=0;k<n;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
printf("The product of the two matrix is\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
}
else
printf("Multiplication is not possible\n");
getch();

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

return 0;
}

Output:
Enter the rows and columns of the first matrix a 2 2
Enter the rows and columns of the first matrix b 2 2
Enter the elements of the first matrix A 1 2 3 4
Enter the elements of the first matrix A 1 2 3 4
The first matrix a is
12
34
The second matrix b is
12
34
The product of the two matrices c is
7 10
15 22

Output:
Enter the rows and columns of the first matrix a 2 3
Enter the rows and columns of the first matrix b 3 2
Multiplication is not possible.

7. Develop a Program to compute Sin(x) using Taylor series


approximation. Compare your result with the built- in Library
function. Print both the results with appropriate messages.

#i ncl ude <s tdio.h>


#i ncl ude <conio.h>
#i ncl ude <math.h>
#de fine PI 3.142
void main()
{
float x,term,s um=0,nume ,denom;
i nt i,degree ;
clrscr() ;
p rintf("enter the value of de gre e\n");
s canf("%d",&degree );
x=deg re e*(P I/180);
nume=x;

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

de nom=1;
i =2;
do
{
term=nume/denom;
nume=-nume*x*x;
denom=de nom*i*(i+1);
sum=sum+te rm;
i=i+2;
}
whi le(fabs (term)>=0.00001) ;
printf("The s ine of %d is %f\n",de gree ,s um);
printf("The s ine function of%d is %f\n",de gree,s in(x));
ge tch() ;
re turn 0;
}

Output:
Enter the value of x (in degrees): 30
Sum of the sine series without using library function sin(30)=
0.499733
Sum of the sine series with using library function sin(30) = 0.500059

Enter the value of x (in degrees): 60


Sum of the sine series without using library function sin(60)=
0.855862
Sum of the sine series with using library function sin(60) = 0.866093

8. Develop a program to sort the given set of N numbers using Bubble


sort.

#i ncl ude <s tdio.h>


#i ncl ude <conio.h>
void main()

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

{
int a[10],n,i,j,te mp;
clrscr();
printf("Enter the Size of an Array :\n");
scanf("%d",&n) ;
printf("Enter the ele ments of an Array:\n ");
for(i=0;i <n;i++)
scanf("%d\n",&a[i]);
printf("The Array e leme nts are :\n");
for(i=0;i <n;i++)
printf("%d\n",a[i]);
for(i=0;i <(n-1) ;i++)
{
for(j=0;j<(n-i-1); j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1 ];
a[j+1]=temp ;
}
}
}
printf("The sorted array ele ments are=%d\n") ;
for(i=0;i <n;i++)
printf("%d\n",a[i]);
ge tch() ;
return 0;
}

Output
1 Ente r the Si ze of an Array: 5
Ente r the e leme nts of an Array: 5 4 3 2 1
The sorted array elements are= 1 2 3 4 5

2 Ente r the Size of an Array: 5


Ente r the e leme nts of an Array: 50 40 30 20 10
The sorted array elements are= 10 20 30 40 50

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

9. Write functions to implement string operations such as compare,


concatenate, string length. Convince the parameter passing
techniques.

#i ncl ude <s tdio.h>


#i ncl ude <conio.h>
#i ncl ude <s tring.h>

void stleng th(char s tr1[]);


void stcomp are(char str1[],char s tr2[]);
void stconcat(char str1[],charstr2[]);

void main()
{
char str1 [20],str2[20];
clrscr();
printf("Enter the First String\n");
scanf("%s ",s tr1);
printf("Enter the Second String \n");
scanf("%s ",s tr2);
stle ngth(str1);
stcompare(str1,str2) ;
stconcat(s tr1,str2);
ge tch() ;
}
void stleng th(char s tr1[])
{
int l ;
l=strle n(s tr1);
printf("The Le ngth of The Stri ng %s is: %d\n",s tr1,l);
}
void stcomp are(char str1[],char s tr2[])
{
int m;
m=s trcmp(str1,s tr2);
if(m==0)
{
printf("String %s and Stri ng %s are equal\n",s tr1,str2);

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

}
el se {
printf("String %s is and String %s \n are not
equal",s tr1,str2);
}

void stconcat(char str1[],char str2[])


{
strcat(str1,s tr2) ;

printf("The C oncate nated String i s: %s \n",str1) ;


}

Output:

Ente r the Fi rs t Stri ng


Comp uter

Ente r the Se cond String


Scie nce

The Leng th of The String computer i s:8

Stri ng Computer String Sci ence are not equal

The Concatenate d String is : computerscie nce

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

10. 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.

#include<stdio.h>
#include<conio.h>
#include<string.h>
struct student
{
char name[20];
int m1,m2,m3,total;
float avg;
};

void main()
{
int i,n ;
struct student s[50];

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

clrscr();
printf("Enter the number of students\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the Details of student %d:\n",i+1);
printf("\nName of the Student:");
scanf("%s",s[i].name);
printf("\nMarks Scored in First Test:\t");
scanf("%d",&s[i].m1);
printf("\nMarks Scored in Second Test:\t");
scanf("%d",&s[i].m2);
printf("\nMarks Scored in Third Test:\t");
scanf("%d",&s[i].m3);
s[i].total=s[i].m1+s[i].m2+s[i].m3;
s[i].avg=s[i].total/3;
}
printf("\n*************************************************************************
*****\n");
printf("\nClass A Student Details are as follows\n");
printf("\n*************************************************************************
*****\n");
printf("\nName\t\tFirst Test|Secont Test|Third
Test|Total|Average|Remarks\n");
printf("\n*************************************************************************
*****\n");
for(i=0;i<n;i++)
{
if(s[i].avg<60)
{
printf("%s\t\t%d\t%d\t%d\t%d\t%4.2f\tB Below
Average\n",s[i].name,s[i].m1,s[i].m2,s[i].m3,s[i].total,s[i].avg);
printf("\n********************************************************************
**********\n");

}
else
{
printf("%s\t\t%d\t%d\t%d\t%d\t%4.2f\tA AboveaAverage\n",
s[i].name,s[i].m1,s[i].m2,s[i].m3,s[i].total,s[i].avg);
printf("\n********************************************************************
**********\n");

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

}
}
getch();
return 0;
}

Output:
Enter the number of students: 2
Enter the Details of student:
Name of the Student: ravikumar
Marks Scored in First Test: 58
Marks Scored in second Test: 58
Marks Scored in First Test: 58
Class A Student Details are as follows:

***********************************************************
Name First Test|Secont Test|Third
Test|Total|Average|Remarks
***********************************************************
Ravikumar 58 58 58 174 58% B Below Average

Enter the number of students: 2


Enter the Details of student:
Name of the Student: ravikumar
Marks Scored in First Test: 58
Marks Scored in second Test: 58
Marks Scored in First Test: 58
Class A Student Details are as follows:

***********************************************************
Name First Test|Secont Test|Third
Test|Total|Average|Remarks
***********************************************************
Ravikumar 65 68 78 211 70.3333% A Above Average

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

11. Develop a program using pointers to compute the sum, mean and

standard

deviation of all Elements stored in an array of n real numbers.

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,i;
float a[20],*ptr,sum,mean,sum=0,sumstd=0;
printf("Enter the array elements\n");
scanf("%d",&n);
printf("Enter the array elements\n");
for(i=0;i<n;i++)
{
scanf("%f",&a[i]);
}
ptr=a;
for(i=0;i<n;i++)
{
sum=sum+*ptr;
ptr++;
}
mean=sum/n;
ptr=a;
for(i=0;i<n;i++)
{
sumstd=sumstd+pow(*ptr-mean),2);
ptr;
}
std=sqrt(sumstd\n);
printf("Sum=%f\n",sum);
printf("Mean=%f\n",mean);
printf("Standard Deviation=%f\n",std);
getch();

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

return 0;
}

OutPut:

Enter the size of the array : 3

Enter the array elements: 1 2 3

Sum = 6.0000

Mean = 2.0000

Standard Deviation=1.732051

12. Write a C program to copy the contents of one file to another file?

#include <stdio.h>
#include <stdlib.h> // For exit()

int main()

FILE *fptr1, *fptr2;

char filename[100], c;

printf("Enter the filename to open for reading \n");

scanf("%s", filename);

fptr1 = fopen(filename, "r");

if (fptr1 == NULL)

printf("Cannot open file %s \n", filename);

exit(0);

printf("Enter the filename to open for writing \n");

scanf("%s", filename);

fptr2 = fopen(filename, "w");

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter
PR OU DH A DE VA R A Y A I NS T I T U T E O F T E CHN OLO G Y
H O S A PE T E – 58 3 2 2 5
D e p a rt m e n t o f Co m pu t e r S ci e n ce & E n g g .

if (fptr2 == NULL)

printf("Cannot open file %s \n", filename);

exit(0);

c = fgetc(fptr1);

while (c != EOF)

fputc(c, fptr2);

c = fgetc(fptr1);

printf("\nContents copied to %s", filename);

fclose(fptr1);

fclose(fptr2);

return 0;

Output:

Enter the filename to open for reading

a.txt

Enter the filename to open for writing

b.txt

Contents copied to b.txt

C O M P U T E R P R O G R A MM I N G L A B O RA T O RY ( 2 2 P O P 1 3/ 2 3 )
C omp uter C enter

You might also like