Professional Documents
Culture Documents
Assignment
Assignment
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
void add();
void rem();
void product();
void print2();
clrscr();
printf("Enter your Choice\n 1.add \n 2.remaider \n 3.produt \n 4.print2 \n");
scanf("%d",&n);
switch(n)
{
case 1:add();break;
case 2:rem();break;
case 3:product();break;
case 4:print2();break;
}
getch();
}
void add()
{
int a,b,c;
printf("input two integers");
scanf("%d %d",&a,&b);
c=a+b;
printf("sum of %d and%d = %d",a,b,c);
}
void rem()
{
int a,b,c;
printf("input two integers");
scanf("%d %d",&a,&b);
c=a%b;
printf("remainder of %d / %d = %d",a,b,c);
}
void product()
{
float a,b,c;
printf("input two floats");
scanf("%f %f",&a,&b);
c=a*b;
printf("remainder of %f * %f = %f",a,b,c);
}
void print2()
{
char ch[20];
printf("input a word");
scanf("%s",&ch);
printf("\n %s \t %s",ch,ch);
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
void rev();
void large();
void oe();
void equal();
printf("Enter your Choice\n 1.rev \n 2.large \n 3.oe \n 4.equal \n");
scanf("%d",&n);
switch(n)
{
case 1:rev();break;
case 2:large();break;
case 3:oe();break;
case 4:equal();break;
}
getch();
}
void rev()
{
long int a,b, rev,c[5],i,j;
rev=0,i=0;
printf("input a 5 digit number");
scanf("%ld",&a);
if(a>9999&& a<99999)
{
b=a;
while(b!=0)
{
c[i]=b%10;
b=(b/10);
i++;
}
for(j=0;j<i;j++)
rev=rev*10+c[j];
printf("Reverse of %ld is %ld",a,rev);
getch();
}
}
void large()
{
float a,b,c;
printf("input two numbers");
scanf("%f%f",&a,&b);
if(a>b)
printf(" %f is greater",a);
else
printf(" %f is greater",b);
}
void oe()
{
int a;
float b;
printf("input an integer");
scanf("%d",&a);
b=a/2;
if(a%2==0)
printf("%f",b);
else
printf("%d",a*3);
}
void equal()
{
int a,b,c;
printf("input three numbers");
scanf("%d%d%d",&a,&b,&c);
if(a==b||b==c||c==a)
printf(" Atleast two are same");
else
printf(" all are different");
}
Q4. Write a program which reads characters from a string and calculates the number of
vowels in it. It should print the string and the number of vowels in it.
#include<stdio.h>
#include<conio.h>
void main()
{
char ch[20];
int i=0,j=0;
printf("input a string");
gets(ch);
while(ch[j]!='\0')
{ switch(ch[j])
{ case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U': i++;
}
j++;
}
printf("The number of vowels in %s \t is %d",ch,i);
getch();
}
Q5. Following is the Taylor-series expansion for sin(x): sin(x) = x − x3/3! + x5/5! − x7 /7!
+
Write a program that reads a value of x and calculates sin(x) using the first 10
terms only and prints out the result.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
long double x,s,sum,f,p,i;
sum=0;
s=f=p=1;
printf("input value of x in radian");
scanf("%lf",&x);
for(i=0;i<=9;i++)
{
sum=sum+s*pow(x,p)/f;
f=f*(p+1)*(p+2);
p=p+2;
s=s*(-1);
}
printf("sin(%lf)=%lf",x,sum);
getch();
}
(a) To generate 10 random numbers between -1.5 and 1.5 and writes them in a file
ran.dat.
(b) To read the data from the file ran.dat (created above) and computes the average of
the
data. It also finds the number of data above the average value.
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
void main()
{
FILE *fp;
int i,j,k;
float sum,avg,n[10],a[10];
sum=avg=0;
clrscr();
printf("Enter 10 numbers");
fp=fopen("ran.dat","w");
randomize();
for( i=0;i<10;i++)
{
n[i]=(((random(100))/100.0)*3-1.5);
printf("\n %f",n[i]);
fprintf(fp,"\n %f",n[i]);
}
fclose(fp);
i=k=0;
fp=fopen("ran.dat","r");
do {
if(!feof(fp))
{
fscanf(fp,"%f",&a[i]);
sum=sum+a[i];
}
i++;
} while(!feof(fp));
avg=sum/10;
printf("\n\n Average=%f\n",avg);
for(j=i-1;j>=0;j--)
{
if(a[j]>avg)
k++;
}
printf("\n\n above average %d\t",k);
getch();
}
Q6. Using structures, write an interactive C program to generate Grade Card for MCA
first semester courses for 20 students of your study centre.
#include<stdio.h>
#include<conio.h>
struct gradeCard
{
int rollno ;
char name[20];
char course[7][10] ;
int theory[7] ;
int asgmt[7] ;
char status[5][15] ;
float marks[7];
float total;
} std[20] ;
void main()
{
int i, j ;
clrscr();
for(i=0; i<20; i++)
{
std[i].total=0;
printf("\n\nEnter student data%d...\n",i+1) ;
printf("Enrollment No.:\t") ;
scanf("%d",&std[i].rollno) ;
printf("Name:\t") ;
scanf("%s",&std[i].name) ;
strcpy(std[i].course[0],"MCS011") ;
strcpy(std[i].course[1],"MCS012") ;
strcpy(std[i].course[2],"MCS013") ;
strcpy(std[i].course[3],"MCS014") ;
strcpy(std[i].course[4],"MCS015") ;
strcpy(std[i].course[5],"MSCL016") ;
strcpy(std[i].course[6],"MSCL017") ;
for(j=0; j<7; j++)
{
printf("%s theory marks:\t",std[i].course[j]) ;
scanf("%d",&std[i].theory[j]) ;
printf("%s asgmt marks:\t",std[i].course[j]) ;
scanf("%d",&std[i].asgmt[j]) ;
std[i].marks[j]=.75*std[i].theory[j]+.25*&std[i].asgmt[j];
if(std[i].marks[j]<40)
strcpy(std[i].status[j],"Failed") ;
else
strcpy(std[i].status[j],"Passed") ;
std[i].total=std[i].total+std[i].marks[j];
}
}
getch() ;
clrscr() ;
printf("See grade card one by one...\n\n") ;
for( i=0; i<20; i++)
{
printf("\n\t\t\t INDIRA GANDHI NATIONAL OPEN
UNIVERSITY\n\n") ;
printf("\n\t\t\t REGIONAL CENTER COCHIN \n\n");
printf("Enrollment No. :\t%d\n\n", std[i].rollno) ;
printf("Name :\t%s\n\n", std[i].name) ;
printf("Subject\tTheory\tAsgmt\ttotal\tStatus\n") ;
for(j=0; j<7; j++)
{
printf("%s\t%d\t%d\t%f\t%s\n", std[i].course[j],
std[i].theory[j], std[i].asgmt[j],
std[i].marks[j], std[i].status[j]);
}
printf("\n\t\t\t Total Marks=%d",std[i].total);
getch() ;
}
}