Professional Documents
Culture Documents
h>
#include <conio.h>
#include <math.h>
void main()
{
/* THIS IS A PROGRAM TO FIND OUT THE
AGGREGATE AND AVERAGE OF A STUDENT IN 8 SUBJECTS */
clrscr();
n=8;
total=0;
avg=total/8.0;
printf("Aggregate is %d \n", total);
printf("Average Mark is %f \n", avg);
getch();
}
enter the student's 1 subject mark
90
enter the student's 2 subject mark
98
enter the student's 3 subject mark
97
enter the student's 4 subject mark
96
enter the student's 5 subject mark
56
enter the student's 6 subject mark
78
enter the student's 7 subject mark
89
enter the student's 8 subject mark
89
Aggregate is 693
Average Mark is 86.625000
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
/* THIS IS A PROGRAM TO FIND OUT THE
AGGREGATE AND AVERAGE OF EACH STUDENT IN 8 SUBJECTS.
IT IS DONE FOR N STUDENTS */
clrscr();
n=8;
puts("enter the number of students \n");
scanf("%d", &ns);
avg=total/8.0;
printf("Aggregate is %d \n", total);
printf("Average Mark is %f \n", avg);
getch();
}
}
enter the number of students
1
enter the 1 student's 1 subject mark
90
enter the 1 student's 2 subject mark
98
enter the 1 student's 3 subject mark
97
enter the 1 student's 4 subject mark
96
enter the 1 student's 5 subject mark
56
enter the 1 student's 6 subject mark
78
enter the 1 student's 7 subject mark
89
enter the 1 student's 8 subject mark
89
Aggregate is 693
Average Mark is 86.625000
# include <stdio.h>
# include <conio.h>
/* array to function */
void main()
{
int a[4] = {10,20,30,40};
clrscr();
printarr(a,4);
getch();
10 20 30 40
# include <stdio.h>
# include <conio.h>
struct stud
{ int regno;
char name[20];
int m[2],t;
};
void main()
{
struct stud s[3];
int i;
clrscr();
for(i=0;i<3;i++)
{
printf("\n enter values for regno, name, m1, m2 \n");
scanf("%d",&s[i].regno);
scanf("%s",s[i].name);
scanf("%d",&s[i].m[0]);
scanf("%d",&s[i].m[1]);
12 sri 87 78 165
34 ravi 90 99 189
45 kavi 34 45 79
#include <stdio.h>
#include <conio.h>
void main()
{
/* THIS IS A PROGRAM TO FOR TEMPERATURE CONVERSION
WITH OPTIONS FOR ENTERING THE TEMPERATURE */
/* function usage */
int fact(int value);
void main()
{
int n,r,x,y,z,result;
clrscr();
n= 7;
r =3;
x = fact(n); y = fact(r); z = fact(n-r);
printf("%d %d %d\n",x,y,z);
result = x/ (y*z);
printf( "ncr value is %d \n ", result);
getch();
5040 6 24
ncr value is 35
# include <stdio.h>
# include <conio.h>
struct stud
{ int regno, m1,m2,t;
char name[20];
};
void main()
{
struct stud s;
FILE *fp;
int i;
clrscr();
/* file open */
fp = fopen("x.dat","w");
/* writing info to file */
for(i=1;i<=3;i++)
{
printf("\n enter values for regno, name, m1, m2 \n");
scanf("%d",&s.regno);
scanf("%s",s.name);
scanf("%d",&s.m1);
scanf("%d",&s.m2);
s.t = s.m1 +s.m2;
fwrite(&s,sizeof(s),1,fp);
}
/* close file */
fclose(fp);
while(fread(&s,sizeof(s),1,fp) != 0)
{
printf("\n regno \t name \t m1 \t m2 \t total \n");
printf("\n %d \t %s \t %d \t %d \t %d \n",s.regno,s.name, s.m1,s.m2,s.t);
}
fclose(fp);
getch();
}
enter values for regno, name, m1, m2
12
srimathi
90
98
enter values for regno, name, m1, m2
34
ravi
89
99
enter values for regno, name, m1, m2
45
mani
78
87
regno name m1 m2 total
12 srimathi 90 98 188
34 ravi 89 99 188
45 mani 78 87 165
# include <stdio.h>
# include <conio.h>
void main()
{
char x[5],y[5];
int i;
clrscr();
for(i=0;i<4;i++)
{
y[i]=getchar();
}
printf("\n the value of y is %s\n",y);
getch();
}
void main()
{
/* THIS IS A PROGRAM TO FIND OUT THE
HIGHEST AND LOWEST MARK IN A SUBJECT */
clrscr();
min=100;
max=0;
if (min>mark)
min=mark;
if (max<mark)
max=mark;
}
void main()
{
int a=5,x,y;
clrscr();
x=a++;
printf(" a= %d,x = %d\n",a,x);
y=++a;
printf(" a= %d,y = %d\n",a,y);
getch();
a= 6,x = 5
a= 7,y = 7
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
/* THIS IS A PROGRAM TO AWARD GRADES FOR
MARKS SCORED USING IF... ELSE.. CONDITION */
int mark;
clrscr();
puts("enter the mark ");
scanf("%d", &mark);
if (mark>=90)
printf("MARK IS %d AND GRADE IS A", mark);
else
if (mark>=80 && mark<90)
printf("MARK IS %d AND GRADE IS B", mark);
else
if (mark>=70 && mark<80)
printf("MARK IS %d AND GRADE IS C", mark);
else
if (mark>=50 && mark<70)
printf("MARK IS %d AND GRADE IS D", mark);
else
printf("MARK IS %d AND GRADE IS FAIL", mark);
getch();
}
void main()
{
/* THIS IS A PROGRAM TO AWARD GRADES FOR
MARKS SCORED USING IF... ELSE.. CONDITION */
clrscr();
puts("enter the mark ");
scanf("%d", &mark);
temp=mark/10;
switch(temp)
{
case 10:
case 9:
printf("MARK IS %d AND GRADE IS A", mark);
break;
case 8:
printf("MARK IS %d AND GRADE IS B", mark);
break;
case 7:
printf("MARK IS %d AND GRADE IS C", mark);
break;
case 6:
case 5:
printf("MARK IS %d AND GRADE IS D", mark);
break;
default:
printf("MARK IS %d AND GRADE IS FAIL", mark);
break;
}
getch();
}
void main()
{
int a,t, *b;
clrscr();
a =5;
b = &a;
/* address of a is stored in b */
t = *b;
/* *b points value of a, however b holds address of a */
Value is in a ,*b, t : 5 5 5
address of value is in &a, b : -12 -12
Value is in a ,*b, t : 10 10 5
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <string.h>
void main()
{
/* THIS IS A PROGRAM TO RANK A SET OF STUDENTS */
clrscr();
clrscr();
/* sorting section */
getch();
}
enter 1 student name & mark -
Sri 98
enter 2 student name & mark -
Ravi 99
enter 3 student name & mark -
Janani 98
enter 4 student name & mark -
Kiruba 85
enter 5 student name & mark -
Vani 100
enter 6 student name & mark -
Kani 45
enter 7 student name & mark -
Dheena 98
enter 8 student name & mark -
Priya 34
enter 9 student name & mark -
Veena 67
enter 10 student name & mark -
Marry 78
RANK ORDER OF THE STUDENTS GIVEN BELOW
int choice;
float p, n, r, si, ci;
clrscr();
void main()
{
/* THIS IS A PROGRAM TO SORT
10 DATA IN ASCENDING ORDER */
clrscr();
/* sorting section */
getch();
}
enter data- 1
34
enter data- 2
-34
enter data- 3
45
enter data- 4
56
enter data- 5
12
enter data- 6
67
enter data- 7
109
enter data- 8
67
enter data- 9
78
enter data- 10
26
DATA GIVEN LISTED BELOW
34 -34 45 56 12 67 109 67 78 26
-34 12 26 34 45 56 67 67 78 109
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
/* THIS IS A PROGRAM TO SORT
10 DATA IN DESCENDING ORDER */
clrscr();
/* sorting section */
getch();
}
enter data- 1
34
enter data- 2
45
enter data- 3
56
enter data- 4
12
enter data- 5
-34
enter data- 6
56
enter data- 7
78
enter data- 8
111
enter data- 9
78
enter data- 10
90
DATA GIVEN LISTED BELOW
34 45 56 12 -34 56 78 111 78 90
111 90 78 78 56 56 45 34 12 -34
# include <stdio.h>
# include <conio.h>
getch();
void myfunc()
{
static int i= 5;
i++;
printf("value of i is %d\n",i);
}
void f1()
{
int i= 5;
i++;
printf("value of i is %d\n",i);
}
without static
value of i is 6
value of i is 6
with static
value of i is 6
value of i is 7
#include <stdio.h>
# include <conio.h>
# include <string.h>
/* string functions */
void main()
{
char x[5],y[5],z[5],w[5];
int len;
clrscr();
strcpy(x,"ravi");
strcpy(w,"ravi");
strcpy(y,x);
/* string copy: strcpy(destination,source) */
printf("\ncopy fn: the source string is %s, the destination string is %s \n",x,y);
strcpy(z,"mathi");
printf("\nthe source string is %s, the destination string before concat is %s \n",x,z);
strcat(z,x);
/* string concatenation : strcat(destination,source) */
len = strlen(x);
/* string length :strlen(variable) */
if (strcmp(w,x)==0)
printf("\nstrings w,x are equal\n");
else
getch();
}
copy fn: the source string is ravi, the destination string is ravi
the source string is ravi, the destination string before concat is mathi
struct stud
{ int regno;
char name[20];
int m1,m2,t;
};
void main()
{
struct stud s[3];
int i;
clrscr();
for(i=0;i<3;i++)
{
printf("\n enter values for regno, name, m1, m2 \n");
scanf("%d",&s[i].regno);
scanf("%s",s[i].name);
scanf("%d",&s[i].m1);
scanf("%d",&s[i].m2);
12 srimathi 90 98 188
34 ravi 89 99 188
45 mani 78 87 165
# include <stdio.h>
# include <conio.h>
struct stud
{ int regno;
char name[20];
int m1,m2,t;
};
void main()
{
struct stud s;
clrscr();
getch();
}
12 srimathi 90 98 188
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
/* THIS IS A PROGRAM TO CALCULATE THE SUM OF FIRST N
NATURAL NUMBERS AND ALSO SUM OF SQUARES OF FIRST N
NATURAL NUMBERS */
int n, sum, i;
float sumsq;
clrscr();
sum=0;
sumsq=0.0;
puts("enter the value of n");
scanf("%d", &n);
for(i=1; i<=n; i++)
{
sum=sum+i;
sumsq=sumsq+i*i;
}
printf("given number is %d \n", n);
printf("sum of first %d natural numbers is %d \n", n, sum);
printf("sum of squares of first %d natural numbers is %10.0f \n", n, sumsq);
getch();
}
int choice;
float cel, faren;
clrscr();
if (choice==1)
{
puts("ENTER THE TEMPERATURE IN DEGREE CENTIGRADE");
scanf("%f", &cel);
faren=9.0/5.0*cel+32;
printf("FOR THE CENTIGRADE TEMP. %f FARENHEIT TEMP. IS %f", cel, faren);
}
else
{
puts("ENTER THE TEMPERATURE IN DEGREE FARENHEIT");
scanf("%f", &faren);
cel=(faren-32)*5.0/9;
printf("FOR THE FARENHEIT TEMP. %f CENTIGRADE TEMP. IS %f", faren, cel );
}
getch();
void main()
{
int x=5, y =50;
clrscr();
void fval(int a)
{
a+= 5;
printf("inside function x -> a value is %d \n",a);
}
Val:
before calling function x value is 5
inside function x -> a value is 10
after calling function x value is 5
Ref:
before calling function y value is 50
inside function y -> b value is 55
after calling function y value is 55
#include<iostream.h>
void main()
{
int j,k;
float l,m;
char n[30];
cin>>j>>k>>l>>m>>n;
cout<<”j =” <<j<<k<<l<<m<<n;
}
# include <stdio.h>
void main()
{
int sum,j;
sum=0;
j = 1;
do
{
sum += j;
j++;
}
while (j <=10);
printf(“sum = %d “, sum);
}
# include <stdio.h>
void main()
{
int sum,j;
sum=0;
j = 1;
while (j<=10)
{
sum += j;
j++;
}
printf(“sum = %d “, sum);
}
# include <stdio.h>
# include <conio.h>
void main()
{
int x=5, y =50;
int l=10,j =20;
clrscr();