You are on page 1of 50

C Language Notes

dprogram to add two values and store in another variable


main()
{
int a,b,c;
a=10;
b=20;
c=a+b;
printf("Val of c is %d",c);
}

program to add two values


main()
{
int a,b;
a=10;
b=20;
printf("val is %d",a+b);
}

Program to add two values using scanf function and store in another variable
main()
{
int a,b,c;
clrscr();
printf("Enter val for a \n");
scanf("%d",&a);
printf("Enter val for b\n");
scanf("%d",&b);
c=a+b;
printf("val of c is %d",c);
}

Program to add two values using scanf function


main()
{
int a,b;
clrscr();
printf("Enter val for a \n");
scanf("%d",&a);
printf("Enter val for b\n");
scanf("%d",&b);
printf("value of a+b is %d",a+b);
}

program to calculate circumfrence of a circle


main()
{
int r,cir;
clrscr();
printf("Enter radius of a circle \n");
scanf("%d",&r);
cir=3.14*(r*r);
printf("circumfrence is %d",cir);

Musicalrocks.tk Page 1
C Language Notes
}
program to calculate area of a triangle
main()
{
int area,b,h;
clrscr();
printf("Enter base \n");
scanf("%d",&b);
printf("Enter height \n");
scanf("%d",&h);
area=0.5*b*h;
printf("area is %d",area);
}

program to calculate area of rectangle


main()
{
int area,l,b;
clrscr();
printf("Enter length \n");
scanf("%d",&l);
printf("Enter breath \n");
scanf("%d",&b);
area=l*b;
printf("area is %d",area);
}

Program to area of square


main()
{
int area,s;
clrscr();
printf("Enter side \n");
scanf("%d",&s);
area=s*s;
printf("area is %d",area);
}

program to convert faheren heat to centigrade


main()
{
int f,c;
clrscr();
printf("Enter f \n");
scanf("%d",&f);
c=f-32;
printf("centigrade is %d",c);
}

program to calculate student details


main()
{
int rno,m,p,c,tot;

Musicalrocks.tk Page 2
C Language Notes
char snm[10];
float avg;
clrscr();
printf("Enter roll number \n");
scanf("%d",&rno);
printf("Enter name of the student \n");
scanf("%s",snm);
printf("Enter marks \n");
scanf("%d%d%d",&m,&p,&c);
tot=m+p+c;
avg=tot/3;
printf("Roll number is %d\n",rno);
printf("Name id %sn",snm);
printf("Total is %d\n",tot);
printf("Average is %f\n",avg);
}

program to calculate employee details


main()
{
int eno;
char enm[10];
float bs,hra,da,ta,net;
clrscr();
printf("Enter employee number \n");
scanf("%d",&eno);
printf("Enter name of the employee \n");
scanf("%s",enm);
printf("Enter basic pay\n");
scanf("%f",&bs);
hra=bs*40/100;
ta=bs*20/100;
da=bs*10/100;
net=bs+hra+ta+da;
printf("employee number is %d\n",eno);
printf("Name id %d\n",enm);
printf("nett amount is %f\n",net);
}

program to calculate current bill


main()
{
int mno;
char holdnm[10];
float cr,pr,gu,net,amt;
clrscr();
printf("Enter metre number \n");
scanf("%d",&mno);
printf("Enter name of the holder \n");
scanf("%s",holdnm);
printf("Enter current units\n");
scanf("%f",&cu);
printf("Enter prev units\n");
scanf("%f",&pu);

Musicalrocks.tk Page 3
C Language Notes
net=cu-pu;
amt=1.25*net;
printf("metre number is %d\n",mno);
printf("Name id %d\n",holdnm);
printf("nett amount to pay is %f\n",net);
}

program on greatest of 2 numbers


main()
{
int a=10,b=20;
if(a>b)
printf("A is big");
else
printf("B is Big");
}

Program to display the greatest of two numbers


main()
{
int a=10,b=20,c=30,big=0;
big=a;
if(b>big)big=a;
if(c>big)big=c;
printf(“Biggest is %d”,big);
}

program to accept and display the greatest of 2 numbers


main()
{
int a,b;
printf("Enter val for a and b\n");
scanf("%d%d",&a,&b);
if(a>b)
printf("A is big");
else
printf("B is Big");
}

program to find even or odd of a given number


main()
{
int n;
printf("Enter val for n\n");
scanf("%d",&n);
if(n%2==0)
printf("Even number");
else
printf("Odd number");
}

program to find the given number is positive or negtive number

Musicalrocks.tk Page 4
C Language Notes
main()
{
int n;
printf("Enter val for n\n");
scanf("%d",&n);
if(n>=0)
printf("Positive number");
else
printf("negtive number");
}

program to find the area of a circle


#define pi 3.14
main()
{
float a,r;
clrscr();
printf("*********************iNPUT*****************************\n");
printf(" ENTER THE RADiUS OF THE CiRCLE R:");
scanf("%f",&r);
a=(pi*r*r);
printf("**********************OUTPUT*****************************\n");
printf("THE AREA OF A CiRCLE iS:%f",a);
getch();
}

program to find the given number is ARMSTRONG number


#include<stdio.h>
main()
{
int a,b,c,d,s,n;
clrscr();
printf("**************************iNPUT********************");
printf("ENTER THE NUMBER\n");
scanf("%d",&n);
a=n/100;
b=n%100;
c=b%10;
d=b/10;
s=a*a*a+c*c*c+d*d*d;
printf("*************************OUTPUT*****************************");
printf("THE VALUE OF S iS:");
printf("%d",s);
if(s==n)
printf("THE ENTERED NO iS ARMSTRONG NUMBER\n");
else
printf("THE ENTERED NO iS NOT AN ARMSTRONG NUMBER\n");
getch();
}

program to go for a choice as follows


1 for add, 2 for sub, 3 for mul, 4 for div, using if condition
#include<stdio.h>
#include<math.h>

Musicalrocks.tk Page 5
C Language Notes
main()
{
int a,b,p,ch;
float m;
clrscr();
printf("\n 1add");
printf("\n 2sub");
printf("\n 3mul");
printf("\n 4div");
printf("\n 5mod div");
printf("\n enter two no's");
scanf("%d%d",&a,&b);
printf("\nenter choice");
scanf("%d",&ch);
if(ch==1)
{
p=a+b;
printf("%d",p);
}
if(ch==2)
{
p=a-b;
printf("%d",p);
}
if(ch==3)
{
p=a*b;
printf("%d",p);
}
if(ch==4)
{
m=(float)a/b;
printf("%f",m);
}
if(ch==5)
{
p=a%b;
printf("%d",p);
}
getch();
}

program on magic numbers .after running the program show the number to any of your friend and the ask him to
imagin any one of the number from 1 to 20 and ask him to say wheather the given number is in the list of stages .if he
say that the number is in the first stage just press enter a counter will count the magic number if he say the number is
not in the stage 1 press onother key in the keyboard .like this repeat all the stages finally the imagined number is
going to display on the screen.

main()
{
int c=0;
char ch;
clrscr();
printf("Stage 1:\n");

Musicalrocks.tk Page 6
C Language Notes
printf("1 3 5 7 9 11 13 15 17 19");
ch=getch();
if(ch==49)
c=c+1;
clrscr();
printf("Stage 2:\n");
printf("2 3 6 10 14 15 17");
ch=getch();
if(ch==49)
c=c+2;
clrscr();
printf("Stage 3: \n");
printf("4 5 6 11 16 18 19");
ch=getch();
if(ch==49)
c=c+4;
clrscr();
printf("Stage 4:\n");
printf("7 11 17 18 19 20");
ch=getch();
if(ch==49)
c=c+6;
clrscr();
printf("Stage 5:\n");
printf("8 9 10 17 18 19 20");
ch=getch();
if(ch==49)
c=c+8;
clrscr();
printf("Stage 6:\n");
printf("12 13 14 15 16 20");
ch=getch();
if(ch==49)
c=c+12;
gotoxy(14,14);
printf(" Ur number is %d",c);
getch();
}

u=total units
ah=above hundred ath=above three hundred
bh=below hundred at=above two hundred
0-100units --->5/-
100-200units-->5.5/-
200-300units-->6.5/-
300-400units-->7/-
100/- will be charged for maintenance.
Find the Electricity bill for 275,250,350,399units*/
main()
{
int u,ah,bh,ath,at;
float a;
clrscr();
printf("Enter Prev units");

Musicalrocks.tk Page 7
C Language Notes
sanf("%d",&pv);
printf("Enter current units");
scanf("%d",cv);
u=cu=pv;
scanf("%d",&u);
if(u<=100)
a=u*5+100;
if((u>100)&&(u<=200))
{
ah=u-100;
bh=u-ah;
a=(ah*5.5)+(bh*5)+100;
}
if((u>200)&&(u<=300))
{
at=u-200;
ah=100;
bh=u-(at+ah);
a=((at*6.5)+(ah*5.5)+(bh*5))+100;
}
if((u>300)&&(u<=400))
{
ath=u-300;
at=100;
ah=100;
bh=u-(ath+at+ah);
a=((ath*7)+(at*6.5)+(ah*5.5)+(bh*5))+100;
}
if(u>=400)
a=3000;
printf(" The total amout is =%f",a);
getch();
}
program using ternary operator
main()
{
int a,b,c;
printf(“Enter val for a and b \n”);
scanf(“%d%d”,&,&b);
c=(a>b)?a:b;
printf(“Val of c is %d”,c);
}

program on greatest of three numbers using ternary operator

main()
{
int a,b,c;
clrscr();
printf(“Enter val for a b and c\n”);
scanf(“%d%d%d”,&a,&b,&c);
(a>b && a>c) ? printf(“A is Big”): (b>a && b>c)?printf(“B is Big”): (c>a && c>b) ? printf(“C is Big”): (printf(“invalid input”);
}

Musicalrocks.tk Page 8
C Language Notes
program on greatest of three numbers using ternary operator
main()
{
int a,b,c,x;
clrscr();
printf(“Enter val for a b and c\n”);
scanf(“%d%d%d”,&a,&b,&c);
x=(a>b && a>c)?a:(b>a && b>c)?b: (c>&& c>b)?c:o;
printf(“Val of x is Biggest “,x);
}

program to find even or odd of a given number


main()
{
int n;
printf(“Enter val for n \n”);
scanf(“%d”,&n);
(n%2==0)?printf(“Even”):printf(“Odd”);
}

program to find even or odd of a given number


main()
{
int n,x;
printf(“Enter val for n \n”);
scanf(“%d”,&n);
x=(n%2==0)?0:1;
(x==0)?printf(“Even”):printf(“Odd”);
}

PROGRAMS ON SWiTCH CASE

Program to find the result of the following operations using the two values 1 for add 2 for sub 3 for mul 4 for div
main()
{
int a,b,c,ch;
clrscr();
printf(“Enter val for a and b \n”);
scanf(“%d%d”,&a,&b);
printf(“Accept your choice as \n”);
printf(“1 for addition 2 for substration 3 for multiplication 4 for division \n”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
c=a+b;
break;
case 2:
c=a-b;
break;
case 3:
c=a*b;
break;
case 4:

Musicalrocks.tk Page 9
C Language Notes
c=a/b;
break;
default:
printf(“invalid choice “);
}
printf(”Val of c is %d”,c);
}

program to purchase soap in a super market according to the following 1 for lux 2 for liril 3 for santoor 4 for fa
main()
{
int qty,ch;
float rate,amt;
clrscr();
printf(“Enter your choice as 1 for lux 2 for liril
3 for santoor 4 for fa\n”);
printf(“Enter your choice \n”);
scanf(“%d”,&ch);
printf(“How many soap you need \n”);
scanf(“%d”,&qty);
switch(ch)
{
case 1:
amt=14.50*qty;
break;
case 2:
amt=12.25*qty;
break;
case 3:
amt=8.25*qty;
break;
case 4:
amt=17.55*qty;
break;
default:
printf(“invalid choice “);
}
printf(“Amount is %f”,amt);
}

Program to find the result of the following operations using the two values a for add s for sub m for mul d for div
main()
{
char ch;
int a,b,c;
clrscr();
printf(“Enter val for a and b \n”);
scanf(“%d%d”,&a,&b);
printf(“Accept your choice as \n”);
printf(“1 for addition 2 for substration 3 for multiplication 4 for division \n”);
scanf(“%c”,&ch);
switch(ch)
{
case ‘a’:

Musicalrocks.tk Page 10
C Language Notes
c=a+b;
break;
case ‘s’:
c=a-b;
break;
case ‘m’:
c=a*b;
break;
case ‘d’:
c=a/b;
break;
default:
printf(“invalid choice “);
}
printf(”Val of c is %d”,c);
}

program to purchase soap in a super market according to the following l for lux r for rexona s for santoor f for fa
main()
{
char ch;
int qty;
float rate,amt;
clrscr();
printf(“Enter your choice as l for lux r for rexona
s for santoor f for fa\n”);
printf(“Enter your choice \n”);
scanf(“%c”,&ch);
printf(“How many soap you need \n”);
scanf(“%d”,&qty);
switch(ch)
{
case ‘l’:
amt=14.50*qty;
break;
case ‘r’:
amt=12.25*qty;
break;
case ‘s’:
amt=8.25*qty;
break;
case ‘f’:
amt=17.55*qty;
break;
default:
printf(“invalid choice “);
}
printf(“Amount is %f”,amt);
}

program on piano using switch case Enter esc to exit from this program
main()
{

Musicalrocks.tk Page 11
C Language Notes
int ch;
ll:
ch=getch();
switch(ch)
{
case 49:
sound(100); break;
case 113:
sound(200); break;
case 50:
sound(300); break;
case 119:
sound(400); break;
case 51:
sound(500); break;
case 101:
sound(600); break;
case 52:
sound(700); break;
case 114:
sound(800); break;
case 53:
sound(900); break;
case 116:
sound(1000); break;
case 54:
sound(1100); break;
case 121:
sound(1200); break;
case 55:
sound(1300); break;
case 117:
sound(1400); break;
case 56:
sound(1500); break;
case 105:
sound(1600); break;
case 57:
sound(1700); break;
case 111:
sound(1800); break;
case 48:
sound(1900); break;
case 112:
sound(2000); break;
case 45:
sound(2100); break;
case 91:
sound(2200); break;
case 61:
sound(2300); break;
case 93:
sound(2400); break;
case 27:
nosound();

Musicalrocks.tk Page 12
C Language Notes
exit();
}
goto ll;
}

program to select the menu of a hotal in the following choice


main()
{
int ch,qty;
float amt;
clrscr();
printf(“Enter your choice as \n”);
printf(“1 for idly 2 for dosa \n”);
printf(“3 for wada 4 for puri \n”);
scanf(“%d”,&ch);
printf(“Enter number of plates \n”);
scanf(“%d”,&qty);
switch(ch)
{
case 1:
amt=6.50*qty;
break;
case 2:
amt=12.35*qty;
break;
case 3:
amt=7.75*qty;
break;
case 4:
amt=9.65*qty;
break;
default:
printf(“invalid choice \n”);
}
printf(“Amout is %f”,amt);
}

program to find the length of a stirng using string function strlen


main()
{
char nm[]=”anand”;
clrscr();
printf(“length of the string is %d”,strlen(nm));
}
program to print a string in reverse format
main()
{
char nm[]=”anand”;
clrscr();
printf(“Reverse of the string is %s”,strrev(nm));
}
program to print a string in upper case
#include<string.h>
main()

Musicalrocks.tk Page 13
C Language Notes
{
char nm[]=”anand”;
clrcsr();
printf(“%s”,strupr(nm));
}

program to print a string inlower case


#include<string.h>
main()
{
char nm[]=”ANAND”;
clrscr();
printf(“%s”,strlwr(nm));
}

program to copy a string from one variable to other


main()
{
char nm[]=”anand”;
char nm1[10];
clrscr();
strcpy(nm1,nm);
printf(“Next variable holds %s string ”,nm1);
}

program to compare two strings


main()
{
char nm1[]=”anand”;
char mn[10];
printf(“Enter your string “);
scanf(“%s”,nm);
if(strcmp(nm,nm1)==0)
printf(“Both are same “);
else
printf(“Both are not equal”);
}

program to concatinate two strings


main()
{
char nm[]=”anand”;
char nm1[]=”ambati”;
printf(“%s”,strcat(nm,nm1));
}

program on puts and gets function


main()
{
char nm[20];
puts(“enter your name “);
gets(nm);
puts(“you have entered”);

Musicalrocks.tk Page 14
C Language Notes
puts(nm);
}

program for difference between two funcations scanf and gets


main()
{
char nm[20];
printf(“Enter name “);
scanf(“%s”,nm);
printf(“Your name is %s\n”,nm);
puts(“Enter your complite name with intial”);
gets(nm);
printf(“Your name is %s”,nm);
}

program on window funcation of conio.h


main()
{
clrscr();
textbackground(9);
window(2,4,22,22);
clreol();
printf(“Hi and welcome to world of computers”);
}

program to get text in colour


main()
{
char nm[]=”anand”;
clrscr();
textcolor(9);
cprintf(“the name is \n”);
cprintf(“%s”,nm);
}

program to get text background and fore ground in colors


main()
{
char nm[]=”anand”;
clrscr();
textattr(423);
cprintf(“Hi and welcome to the world of comters”);
}

program using goto label to print 1 to 10 numbers


main()
{
int i=1;
ll:
printf(“%d\n”,i);
i++;
if(i>=10)
Exit();

Musicalrocks.tk Page 15
C Language Notes
Else
Goto ll;
}

program to print odd numbers using goto label


main()
{
int i=1;
ll:
printf(“%d\n”,i);
i=i+2;
if(i>=10)
Exit();
Else
goto ll;
}

program to print even numbers using goto label


main()
{
int i=0;
ll:
printf(“%d\n”,i);
i=i+2;
if(i>=10)
Exit();
Else
goto ll;
}
program to print sum of 1 to 10 numbers
main()
{
int i=1,sum;
ll:
sum=sum+i;
i++;
if(i>=10)
{
printf(“Sum is %d”,sum);
Exit();
}
Else
Goto ll;
}

program to add sumof even numbers


main()
{
int i=0,sum;
ll:
sum=sum+i;
i=i+2;
if(i>=10)
{

Musicalrocks.tk Page 16
C Language Notes
printf(“Sum is %d”,sum);
exit();
}
else
goto ll;
}

program to print sum of odd numbers


main()
{
int i=1,sum=0;
anand:
sum=sum+i;
i=i+2;
if(i>=10)
{
Printf(“Sum of odd numbers is %d”,sum);
Exit();
}
Else
Goto anand;
}

program to print 5 10 15 20 …….50


main()
{
int i=5;
xx:
printf(“%d\n”,i);
i=i+5;
if(i>=50)
Exit();
Else
Goto xx;
}

program to print sum of 5 10 15 20 25 30 35 40 45 50


main()
{
int i=5,sum=0;
abc:
sum=sum+il
i=i+5;
if(i>=50)
{
Printf(“sumis %d”,sum);
Exit();
}
Else
Goto abc;
}

program to print 1 to 10 numbers using while loop


main()

Musicalrocks.tk Page 17
C Language Notes
{
int i=1;
clrscr();
while(i<=10)
{
printf(“%d\n”,i);
i++;
}
}

program to print 1 to 10 odd number using while loop


main()
{
int i=1;
clrscr();
whie(i<=10)
{
printf(“%d\n”,i);
i=i+2;
}
}

program to print 1 to 10 even numbers using while loop


main()
{
int i=0;
while(i<=10)
{
printf(“%d\n”,i);
i=i+2;
}
}

program to print sum of 1 to 10 odd numbers using while loop


main()
{
int i=1,sum=0;
clrscr();
while(i<=10)
{
sum=sum=i;
i++;
}
printf(“Sum is %d”,sum);
}

program to print sum of 1 to 10 even numbers usin whle loop


main()
{
int i=1,sum=0;
clrscr();
while(i<=10)
{
sum=sum=i;

Musicalrocks.tk Page 18
C Language Notes
i++;
}
printf(“Sum is %d”,sum);
}

program to print 1 to 10 numbers using do…..while loop


main()
main()
{
int i=1;
clrscr();
do
{
printf(“%d\n”,i);
i++;
} while(i<=10);
}

program to print 1 to 10 odd number using do while loop


main()
{
int i=1;
clrscr();
do
{
printf(“%d\n”,i);
i=i+2;
} whie(i<=10);
}

program to print 1 to 10 even numbers using do while loop


main()
{
int i=0;
do
{
printf(“%d\n”,i);
i=i+2;
} while(i<=10);
}

program to print sum of 1 to 10 odd numbers using do while loop


main()
{
int i=1,sum=0;
clrscr();
do
{
sum=sum=i;
i++;
} while(i<=10);
printf(“Sum is %d”,sum);
}

Musicalrocks.tk Page 19
C Language Notes
program to print sum of 1 to 10 even numbers using do while loop
main()
{
int i=0,sum=0;
clrscr();
do
{
sum=sum=i;
i++;
} while(i<=10);
printf(“Sum is %d”,sum);
}

program to print 1 to 10 numbers using for loop


main()
{
int i;
for(i=1;i<=10;i++)
{
printf(“%d\n”,i);
}
}

program to print 1 to 10 even numbers using for loop


main()
{
int i;
for(i=0;i<=10;i=i+2)
{
printf(“%d\n”,i);
}
}

program to print 1 to 10 odd numbers using for loop


main()
{
int i;
for(i=1;i<=10;i=i+2)
{
printf(“%d\n”,i);
}
}

program to print sum of 1 to 10 odd numbers using for loop


main()
{
int i;
for(i=1;i<=10;i=i+2)
{
sum=sum+i;
}

Musicalrocks.tk Page 20
C Language Notes
printf(“Sum is %d”,sum);
}

program to print sum of 1 to 10 even numbers using for loop


main()
{
int i;
for(i=0;i<=10;i=i+2)
{
sum=sum+i;
}
printf(“Sum is %d”,sum);
}

program to find the factorial of a given number using while loop


main()
{
int fact=1,i=1;
clrscr();
printf(“Enter the number for which u need the factorail \n”);
scanf(“%d”,&n);
while(i<=n)
{
fact=fact*i;
i++;
}
printf(‘factorail val of %d is %d”,n,fact);
}

program to find the factorial of a given number using do while loop


main()
{
int fact=1,i=1;
clrscr();
printf(“Enter the number for which u need the factorail \n”);
scanf(“%d”,&n);
do
{
fact=fact*i;
i++;
} while(i<=n);
printf(‘factorail val of %d is %d”,n,fact);
}

program to find the factorial of a given number using do while loop


main()
{
int fact=1,i=1;
clrscr();
printf(“Enter the number for which u need the factorail \n”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{

Musicalrocks.tk Page 21
C Language Notes
fact=fact*i;
}
printf(‘factorail val of %d is %d”,n,fact);
}

program to print mathamatical table of a given number using while loop


main()
{
int i=1,res,n;
printf(“Enter which table u need \n”);s
scanf(“%d”,&n);
while(i<=10)
{
res=n*i;
printf(“%d*%d=%d”,n,i,res);
i++;
}
}

program to print mathamatical table of a given number using do while loop


main()
{
int i=1,res,n;
printf(“Enter which table u need \n”);s
scanf(“%d”,&n);
do
{
res=n*i;
printf(“%d*%d=%d”,n,i,res);
i++;
} while(i<=10);
}

program to print mathamatical table of given number using for loop


main()
{
int i=1,res,n;
printf(“Enter which table u need \n”);s
scanf(“%d”,&n);
for(i=1;i<=10;i++)
{
res=n*i;
printf(“%d*%d=%d”,n,i,res);
}
}

program to print fibonicci series of given range using while loop


main()
{
int i=1,f1=0,f2=1,f3=0,n;
clrscr();
prntf(“Enter the range of the series\n”);
scanf(“%d”,&n);
while(i<=n)

Musicalrocks.tk Page 22
C Language Notes
{
printf(“%d\n”,f3);
f1=f2;
f2=f3;
f3=f1+f2;
i++;
}
}

program to print fibonicci series of given range using do while loop


main()
{
int i=1,f1=0,f2=1,f3=0,n;
clrscr();
prntf(“Enter the range of the series\n”);
scanf(“%d”,&n);
do
{
printf(“%d\n”,f3);
f1=f2;
f2=f3;
f3=f1+f2;
i++;
} while(i<=n);
}

program to print fibonicci series of given range using for loop


main()
{
int i=1,f1=0,f2=1,f3=0,n;
clrscr();
prntf(“Enter the range of the series\n”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
printf(“%d\n”,f3);
f1=f2;
f2=f3;
f3=f1+f2;
}
}

program to convert binary to decimal of a given number


main()
{
int i,n,bin[8],r,bina[8];
clrscr();
printf("Enter val for n\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
r=n/2;
bin[i]=n%2;

Musicalrocks.tk Page 23
C Language Notes
n=r;
printf("%d",bin[i]);
}
for(i=0;i<n;i++)
{
bina[i]=bin[n-1-i];
}
for(i=0;i<n;i++)
{
printf("%d",bina[i]);
}
}

program to create a window using window funcation from conio.h


#include<stdlib.h>
main()
{
char nm[]=”anand”;
int i,j,k;
clrscr();
window(5,5,43,23);
gotoxy(40,12);
for(k=0;k<12;k++)
{
for(j=0;j<12;j++)
{
for(i=0;i<strlen(nm);i++)
{
textcolor(i);
cprintf(“%s”,nm[i]);
delay(99);
textbackground(random(20));
}
}
}
}
program to check the given number is plaendrome or not

main()
{
int n,m,r,s=0;
clrscr();
printf("Enter val for n\n");
scanf("%d",&n);
m=n;
while(m!=0)
{
r=m%10;
s=s*10+r;
m=m/10;
}
printf("reverse number is %d\n",s);
if(s==n)
printf("number is palendrome");

Musicalrocks.tk Page 24
C Language Notes
else
printf("Not palendrome");
}

program tp find the sum of digits of number


main()
{
int n,sum=0,q;
printf(“Enter val for n\n”);
scanf(“%d”,&n);
while(n>0)
{
q=n%10;
sum=sum+q;
n=n/10;
}
printf(“sum is %d”,sum);
}

proram to find wheather the given number is plendrome or not


main()
{
int q,sum=0,n,t;
printf("Enter val for n\n");
scanf("%d",&n);
t=n;
while(n>0)
{
q=n%10;
sum=sum*10+q;
n=n/10;
}
if(sum==t)
printf("Palandrome");
else
printf("not a palandrome");
}

program on pascal trianlge

main()
{
int binom,p,q,r,x;
binom=1;
q=0;
printf("Enter how many row u need \n");
scanf("%d",&p);
while(q<p)
{
for(r=40-3*q;r>0;r--)
printf(" ");
for(x=0;x<=q;++x)
{

Musicalrocks.tk Page 25
C Language Notes
if((x==0)||(q==0))
binom=1;
else
binom=(binom*(q-x+1))/x;
printf("%6d",binom);
}
printf("\n");
++q;
}}

program to verify the given number is prime or not


main()
{
int n,i,cnt=0;
printf("Enter val for n \n");
scanf("%d",&n);
for(i=2;i<=n-1;i++)
{
if(n%i==0)
cnt=cnt+1;
}
if(cnt==0)
printf("prime");
else
printf("Not prime");
}

progrm to find the LCM

main()
{
int a,b,c=2, k=1,d;
printf("Enter three number s\n");
scanf("%d%d%d",&a,&b,&d);
do
{
if((a%c==0)||(b%c==0)||(d%c==0))
{
k=c*k;
if(a%c==0)a=a/c;
if(b%c==0)b=b/c;
if(d%c==0)d=d/c;
}
else
c++;
}
while((c<=a)||(c<=b)||(c<=d));
printf("LCM is %d",k);
}

program to display prime number series


main()
{
int n1,n2,i,j;

Musicalrocks.tk Page 26
C Language Notes
printf(“Enter values for n1 and n2”);
scanf(“%d%d”,&n1,&n2);
for(i=n1;i<=n2;i++)
{
for(j=2;j<=i1;j++)
{
if(i%j==0)
break;
else
if(j==i-1)
printf(“%d\n”,i);
}
}
}

program to print the format check the program


main()
{
char nm[10];
int i,j,len,k=0;
clrscr();
printf("Enter name \n");
scanf("%s",nm);
len=strlen(nm);
for(i=0;i<=len;i++)
{
printf("\n");
for(j=0;j<len-k;j++)
printf("%c",nm[j]);
for(j=0;j<2*k;j++)
printf(" ");
for(j=len-1-k;j>=0;j--)
printf("%c",nm[j]);
k++;
}
}

program to sum the digits of a number


main()
{
n,sum=0,q;
printf("Enter val for n\n");
scanf("%d",&n);
while(n>0)
{
q=n%10;
sum=sum+q;
n=n/10;
}
printf("Sum is %d",sum);
}

program to print range of mathamitical table using for loop


main()

Musicalrocks.tk Page 27
C Language Notes
{
int i,j,res,st,end;
clrscr();
printf(“Enter val for st \n”);
scanf(“%d”,&st);
printf(“Enter val for end \n”);
scanf(“%d”,&end);
for(i=st;i<=end;i++)
{
for(j=1;j<=10;j++)
{
res=st*i;
printf(“%d*%d=%d\n”,st,i,res);
}
st++;
getch();
}
}

program to print range of mathamitical table using while loop


main()
{
int ,res,st,end,j=1;
clrscr();
printf(“Enter val for st \n”);
scanf(“%d”,&st);
printf(“Enter val for end \n”);
scanf(“%d”,&end);
while(st<=end)
{
i=1;
while(i<=10)
{
res=st*i;
printf(“%d*%d=%d”,st,i,res);
i++;
}
st++;
}
}

program to add all the elements in array a[5]


main()
{
int a[5],i,sum=0;
clrscr();
printf(“Enter array elements \n”);
for(i=0;i<5;i++)
{
scanf(“%d”,&a[i]);
}
for(i=0;i<5;i++)
{
sum=sum+a[i];

Musicalrocks.tk Page 28
C Language Notes
}
printf(“Sum is %d”,sum);
}
program on addition of two array and storing the result in the third array
main()
{
int a[5]={4,3,5,6,2};
int b[5]={6,8,7,9,1};
int c[5],i;
clrscr();
for(i=0;i<5;i++)
{
c[i]=a[i]+b[i];
printf(“%d\t”,c[i]);
}
}
program to find biggest element in array
main()
{
int a[5],i,big=0;
clrscr();
printf(“Enter element in array \n”);
for(i=0;i<5;i++)
{
scanf(“%d”,&a[i]);
}
for(i=0;i<5;i++)
{
if(a[i]>big)
big=a[i];
}
printf(“Biggest element is %d”,big);
}

program to find smallest element in array


main()
{
int a[5],i,small;
clrscr();
printf(“Enter element in array \n”);
for(i=0;i<5;i++)
{
scanf(“%d”,&a[i]);
}
for(i=0;i<5;i++)
{
if(a[i]<small)
small=a[i];
}
printf(“smallest element is %d”,small);
}

program to sort the elements in decending order


main()

Musicalrocks.tk Page 29
C Language Notes
{
int a[5]={4,5,7,6,2,8};
int i,j,temp;
clrscr();
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf(“Elements after sorting \n”);
for(i=0;i<5;i++)
{
printf(“%d\t”,a[i]);
}

program to sort the elements in ascending order


main()
{
int a[5]={4,5,7,6,2,8};
int i,j,temp;
clrscr();
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf(“Elements after sorting \n”);
for(i=0;i<5;i++)
{
printf(“%d\t”,a[i]);
}

program to replace a selected element from the list of array


main()
{
int rep,fnd,i,j;
int a[5]={8,7,5,9,3};
clrscr();
printf(“Enter element to find\n”);
scanf(“%d”,&fnd);

Musicalrocks.tk Page 30
C Language Notes
printf(‘Enter element to replace \n”);
scanf(“%d”,&rep);
for(i=0;i<5;i++)
{
if(a[i]==fnd)
a[i]=rep;
}
printf(“After replacing the elements are \n”);
for(i=0;i<5;i++)
{
printf(‘”%d\t”,a[i]);
}
}

program to delete a element in the array list


main()
{
int fnd,i;
int a[5]={8,5,4,9,7};
clrscr();
printf(“Enter element to find \n”);
scanf(“%d”,&fnd);
for(i=0;i<5;i++)
{
if(a[i]==fnd)
a[i]==0;
}
printf(“After deleting the element the array list \n”);
for(i=0;i<5;i++)
{
printf(“%d\t”,a[i]);
}
}

program to accept double dimension array and display the sum of all the elements
main()
{
int a[3][3],i,j,sum=0;
clrscr();
printf(“Enter array element \n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf(“%d”,&a[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
sum=sum+a[i][j];
}
}

Musicalrocks.tk Page 31
C Language Notes
printf(“Sum of all the elements in the array is %d”,sum);
}

program to add the elements of the two double dimension arrray and display the result in the third array
main()
{
int a[3][3]={{2,4,3},{4,5,7},{7,6,8}};
int b[3][3]={{4,6,3},{6,8,5},{4,6,8}};
int c[3][3];
int i,j,sum=0;
clrscr();
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf(“The resultant array is \n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“%d\t”,c[i][j]);
}
printf(“\n”);
}
}
program to find the biggest elenemt in a double dimension array
main()
{
int a[3][3];
int i,j,big=0;
clrscr();
printf(“Enter elements in array \n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf(“%d”,&a[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(a[i]>big)
big=a[i][j];
}
}
printf(“The biggest element is %d”,big);
}
program to find the smallest elenemt in a double dimension array
main()

Musicalrocks.tk Page 32
C Language Notes
{
int a[3][3];
int i,j,small;
clrscr();
printf(“Enter elements in array \n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf(“%d”,&a[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(a[i]>small)
small=a[i][j];
}
}
printf(“The smallest element is %d”,small);
}

program to sort in decending order


main()
{
int a[3][3]={{4,6,5},{2,3,4},{6,8,7}};
int i,j,temp;
clrscr();
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
{
for(l=0;l<3;l++)
{
if(a[i][j]>a[k][l])
{
tempa=[i][j];
a[i][j]=a[k][l];
a[k][l]=temp;
}
}
}
}
}
printf(“After sorting \n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“%d\t”,a[i][j]);
}
printf(“\n”);

Musicalrocks.tk Page 33
C Language Notes
}
}

program to sort in ascending order


main()
{
int a[3][3]={{4,6,5},{2,3,4},{6,8,7}};
int i,j,temp;
clrscr();
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
{
for(l=0;l<3;l++)
{
if(a[i][j]<a[k][l])
{
tempa=[i][j];
a[i][j]=a[k][l];
a[k][l]=temp;
}
}
}
}
}
printf(“After sorting \n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“%d\t”,a[i][j]);
}
printf(“\n”);
}
}

program to display the lower triangle of array


main()
{
int a[3][3]={{,7,5,4},{4,5,6},{7,5,8}};
int i,j;
clrscr();
printf(“Lower triangle is \n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i>=j)
printf(“%d\t”,a[i][j]);
}
}
printf(“\n”);

Musicalrocks.tk Page 34
C Language Notes
}

program to display the upper triangle of array


main()
{
int a[3][3]={{,7,5,4},{4,5,6},{7,5,8}};
int i,j;
clrscr();
printf(“upper triangle is \n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i<=j)
printf(“%d\t”,a[i][j]);
}
}
printf(“\n”);
}

program to find element in array and relpace it with other element


main()
{
int a[3][3]={{,7,5,4},{4,5,6},{7,5,8}};
int i,j,fnd,rep;
printf(“Enter element to find \n”);
scanf(“%d”,&fnd);
printf(“Enter element to replace \n”);
scanf(“%d”,&rep);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(a[i][j]==fnd)
a[i][j]=rep;
}
}
printf(“After replacing the elements are \n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“%d\t”,a[i][j]);
}
printf(“\n”);
}
}

program to delete an element in array


main()
{
int a[3][3]={{5,3,6},{2,4,3},{6,9,4}};
int i,j,fnd;
clrscr();

Musicalrocks.tk Page 35
C Language Notes
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(a[i][j]==fnd)
a[i][j]=o;
}
}
printf(“After deleting element\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“%d\t”,a[i[j]);
}
printf(“\n”);
}
}

program multiply two arrays and store the result in third array
main()
{
int a[3][3] , b[3][3];
int c[3][3],i,j,k;
clrscr();
printf(“Enter elements in array A\n”);
for(i=0;i<3;i++){
for(j=0;j<3;j++)
{
scanf(“%d”,&a[i][j]);
}
}
printf(“Enter array B\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf(“%d”,&b[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=0;
for(k=0;k<3;k++)
{
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
}
}
printf(“Element after calculating \n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)

Musicalrocks.tk Page 36
C Language Notes
{
printf(“%d\t”,c[i][j]);
}
printf(\n”);
}
}

program to tronspose a matrix


#include<stdio.h>
main()
{
int i,j,a[3][3],b[3][3];
clrscr();
printf(“Emter array elements\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
b[i][j]=a[j][i];
}
}
printf("transpose of a matrix");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
getch();
}

program on array to display weather the given matrix is symmetric or not

main()
{
int i,j,flag;
int b[3][3];
int a[3][3]={{2,3,4},{4,5,6},{2,4,6}};
clrscr();
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(a[i][j]!=b[i][j])
flag=1;

Musicalrocks.tk Page 37
C Language Notes
}
}
if(flag)
printf("Not symmetric ");
else
printf("Symmetric ");
}

program to norm the martix


main()
{
int a[3][3],i,j,sum=0;
float norm;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf(“%d”,&a[i][j]);
sum=sum+a[i][j]*a[i][j];
}
}
norm=(float)sqrt(sum);
printf(“Norm of a matrix is %d”,norm);
}

program to demonstrate the types of functions


1**
main()
{
add();
}
add()
{
int a=10,b=20,c;
c=a+b;
printf(“Val of c is %d”,c);
}

method 2**

main()
{
int a=10,b=20;
void add(int,int);
add(a,b);
}
add(int x,int y)
{
int z;
z=x+y;
printf(“val of z is %d”,z);
}

Musicalrocks.tk Page 38
C Language Notes
method 3**
main()
{
int c;
int add();
c=add();
printf(“Val of c is %d”,c);
}
int add()
{
int a=10,b=20,c;
c=a+b;
return( c );
}

method 4**
main()
{
int a=10,b=20,c;
int add(int,int);
c=add(a,b);
printf(“val of c is %d”,c);
}
int add(int x,int y)
{
int z;
z=x+y;
return( z );
}

different sample
main()
{
int a=10,b=20,c;
int add(int,int)
c=add(a,b);
printf(“val of c is %d”,c);
}
int add(int x,int y)
{
return( x+y );
}

program to swap two numbers


main()
{
swap();
}
swap()
{
int a=10,b=20,temp;
temp=a;
a=b;
b=temp;

Musicalrocks.tk Page 39
C Language Notes
printf(“values after swaping are %d and %d”,a,b);
}
proram on swap
main()
{
int a=10,b=20;
void swap(int,int);
swap(a,b);
printf(“after swaping the values are %d and %d”,a,b);
}
swap(int x,int y)
{
int temp;
temp=x;
x=y;
y=temp;
}
program on function to display factorial val ue
main()
{
facto();
}
facto()
{
int n,i=1,fact=1;
printf(“Enter val for n\n”);
scanf(“%d”,&n);
while(i<=n)
{
fact=fact*i;
i++;
}
printf(“factorial val is %d”,fact);
}

program on function to display the factorial value


main()
{
int n;
void facto(int);
clrscr();
printf(“Enter val for n\n”);
scanf(“%d”,&n);
facto(n);
}
facto(int x)
{
int fact=1,i=1;
do
{
fact=fact*i;
i++;
}while(i<=x);
printf(“factorial val is %d”,fact);

Musicalrocks.tk Page 40
C Language Notes
}

program on function to display the fatorial value


main()
{
long f;
long facto();
f=facto();
printf(“factoiral is %ld”,fact);
}
long facto()
{
long n,fact=1;
int i;
printf(“Enter val for n\n”);
scanf(“%ld”,&n);
for(i=1;i<=n;i++)
{
fact=fact*i;
}
return(fact);
}

program on function display the factorial value


main()
{
long f,n;
long facto(long);
clrscr();
printf(“Enter val for n \n”);
scanf(“%ld”,&n);
f=facto(n);
printf(“Factorial val is %ld”,fact);
}
long facto(long x)
{
long fact=1;
int i;
for(i=1;i<=x;i++)
{
fact=fact*i;
}
return(fact);
}

program on function display the fibonicci series


main()
{
fibo();
}
fibo()
{
int n,i,f1=0,f2=1,f3=0;
clrscr();

Musicalrocks.tk Page 41
C Language Notes
for(i=1;i<=n;i++)
{
printf(“%d\n”,f3);
f1=f2;
f2=f3;
f3=f1+f2;
}
}

program on functions display the fibonicci series


main()
{
int n;
void fibo(int);
printf(“Enter val for n\n”0;
scanf(“%d”,&n);
fibo(n);
}
fibo(int x)
{
int i,f1=0,f2=1,f3=0;
clrscr();
for(i=0;i<x;i++)
{
printf(“%d\n”,f3);
f1=f2;
f2=f3;
f3=f1+f2;
}
}

program on functions mathamatical table


main()
{
void mat_table();
mat_table();
}
void mat_table()
{
int n,i,res;
clrscr();
printf(“Enter val for n \n”);
scanf(“%d”,&n);
for(i=1;i<=10;i++)
{
res=n*i;
printf(“%d*%d=%d”,n,i,res);
}
}

proram on functions display the mathamatical table


main()

Musicalrocks.tk Page 42
C Language Notes
{
int n;
void mat_table(int);
printf(“Enter val for n \n”);
scanf(“%d”,&n);
mat_table(n);
}
void mat_table(int x)
{
int res,i;

for(i=1;i<=10;i++)
{
res=x*i;
printf(“%d*%d=%d\n”,x,i,res);
}
}

program on function to diplay the factoiral value using recursion mathod


main()
{
int x,y;
int facto(int);
printf(“Enter val for x \n”);
scanf(“%d”,&x);
y=facto(x);
printf(“Val is %d”,y);
}
int facto(int n)
{
int fact;
if((n==1)||(n==0))
return(1);
else
{
fact=n*facto(n-1);
}
return(fact);
}

program to disp what is pointer and display the value of a variable anf value of a variable using pointer
main()
{
int a=10,*b;
printf(“val of a is %d\n”,a);
printf(“Address of a is %d\n”,&a);
b=&a;
printf(“Val of b is %d\n”,b);
printf(“Address of b is %d\n”,&b);
printf(“Val of b becomes %d when we place a pointer”,*b);
}

porgram on pointer to add two numbers


main()

Musicalrocks.tk Page 43
C Language Notes
{
int a=10,b=20,*aa,*bb,c;
aa=&a;
bb=&b;
c=*aa+*bb;
printf(“Val of c is %d”,c);
}
program on pointer using array and display the sum of array elements
main()
{
int a[5]={2,4,5,6,3};
int i,j,sum=0,*p;
clrscr();
p=&a;
for(i=0;i<5;i++)
{
sum=sum+*p++;
}
printf("Sum is %d",sum);
}

program on pointer to swap two numbers


main()
{
int a=10,b=20;
swap(&a,&b);
}
swap(int *a,int *b)
{
int temp;
temp=a;
a=b;
b=temp;
printf(“Val of a and b are %d and %d”,a,b);
}

prorgam on pointer to add two arrray and store the result in the third array
main()
{
int a[5]={2,4,5,6,3};
int b[5]={4,3,5,6,7};
int c[5],i,*pp,*qq;
clrscr();
pp=&a;
qq=&b;
for(i=0;i<5;i++)
{
c[i]=*pp++ + *qq++
printf("%d\t",c[i]);
}
}

program on pointer to display the biggest of array elements


main()

Musicalrocks.tk Page 44
C Language Notes
{
int a[5]={2,4,5,6,3};
int i,*pp,big=0;
clrscr();
pp=&a;
for(i=0;i<5;i++)
{
if(*pp++>big)
big= *pp++;
}
printf("Biggest element is %d",big);
}

program on pointer to add two double dim array and store the result in the third array
main()
{
int a[3][3]={{18,10,19},{18,71,16},{15,14,31}};
int i,j,*pp,sum=0;
pp=&a;
clrscr();
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
sum=sum+*pp++;
}
}
printf("Sum is %d",sum);
}

program to display the fatorial of a given number using using functions and pointers with (call by refernce)
main()
{
int fact=1,n,i;
clrscr();
printf(“Enter val for n \n”);
scanf(“%d”,&n);
facto(&n);
}
facto(int *p)
{
int fact=1,i=1;
while(i<=*p)
{
fact=fact*i;
i++;
}
printf(“Factorial val is %d”,fact);
}

program on structure to display the sum of two globel variables


struct ABC
{

Musicalrocks.tk Page 45
C Language Notes
int a,b;
};
main()
{
struct ABC xyz;
int c;
xyz.a=10;
xyz.b=20;
c=xyz.a+xyz.b;
printf(“Val of c is %d”,c);
}

program on structure to add two numbers


struct XYZ
{
int a,b;
};
main()
{
struct XYZ xx;
int c;
printf(“Enter val for a\n”);
scanf(“%d”,&xx.a);
printf(“Enter val for b \n”);
scanf(“%d”,&xx.b);
c=xx.a+xx.b;
printf(“Val of c is %d”,c);
}

program on structure to display the sumof two numbers


struct ANAND
{
int a,b;
};
main()
{
struct ANAND aaa;
aaa.a=10;
aaa.b=20;
if(aaa.a>aaa.b)
printf(“VAL of a is Big”);
else
printf(“Val of b is big”);
}

program on structure to calculate the student details and display the result
struct STD
{
int rno,m,p,c,tot;
float avg;
char nm[10];
};
main()
{

Musicalrocks.tk Page 46
C Language Notes
struct STD ss;
clrscr();
printf(“Enter roll number \n”);
scanf(“%d”,&ss.rno);
printf(“Enter Name \n”);
scanf(“%s”,ss.nm);
printf(“Enter marks \n”);
scanf(“%d%d%d”,&ss.m,&ss.p,&ss.c);
ss.tot=ss.m+ss.p+ss.c;
ss.avg=ss.tot/3;
printf(“Student name is %s\n”,ssnm);
printf(“Total is %d\n”,ss.tot);
printf(“Average is %f\n”,ss.avg);
}

program on structure to display the eployee details


struct EMP
{
int eno;
char nm[10];
float bs,hra,da,ta,net;
}ee;
main()
{
printf(“Enter employee number \n”);
scanf(“%d”,&ee.eno);
printf(“Enter name of the employee \n”);
scanf(“%s”,ssnm);
printf(“Enter basic pay \n”);
scanf(“%f”,&ee.bs);
ee.hra=ee.bs*30/100;
ee.da=ee.bs*20/100;
ee.ta=ee.bs*10/100;
ee.net=ee.bs+ee.hra+ee.da+ee.ta;
printf(“Net amount is %f\n”,ee.net);
}

program on structure to add two array and display the result


struct ARR
{
int a[5],b[5],c[5];
};
main()
{
struct ARR ar;
int i;
clrscr();
printf(“Enter array A\n”);
for(i=0;i<5;i++)
{
scanf(“%d”,&ar.a[i]);
}
printf(“Enter array B \n”);
for(i=0;i<5;i++)

Musicalrocks.tk Page 47
C Language Notes
{
scanf(“%d”,&ar.b[i]);
}
for(i=0;i<5;i++)
{
ar.c[i]=ar.a[i]+ar.b[i];
}
printf(“Enter vals for resultant array are \n”);
for(i=0;i<5;i++)
{
printf(“%d\t”,ar.c[i]);
}
}

proram on structure to add two double dim arrays


struct ARR
{
int a[3][3],b[3][3],c[3][3];
};
main()
{
struct ARR ar;
int i,j,k;
clrscr();
printf(“Enter array A\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf(“%d”,&ar.a[i][j]);
}
}
printf(“Enter array B\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf(“%d”,&ar.b[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
ar.c[i][j]=0;
for(k=0;k<3;k++)
{
ar.c[i][j]=ar.c[i][j]+(ar.a[i][k]*ar.b[k][j]);
}
}
}
printf(“The resultant array is\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)

Musicalrocks.tk Page 48
C Language Notes
{
printf(“%d\t”,ar.c[i][j]);
}
printf(“\n”);
}
}

program on structure using pointers


struct STD
{
int rno,m,p,c,tot;
float avg;
};
main()
{
struct STD pp;
struct STD *ss;
ss=&pp;
printf(“Enter marks \n”);
scanf(“%d%d%d”,&ss->m,&ss->p,&ss->c);
ss->tot=ss->m+ss->p+ss->c;
ss->avg=ss->tot/3;
printf(“Total is %d\n”,ss->tot);
printf(“Average is %f\n”,ss->avg);
}

program on structure to calculate employee details using pointers


struct EMP
{
int eno;
float bs,hra,da,ta,net;
};
main()
{
struct EMP ee;
struct EMP *pp;
pp=&ee;
printf(“Enter employee number \n”);
scanf(“%d”,&pp->eno);
printf(“Enter employee basic pay \n”);
scanf(“%f”,&pp->bs);
ee->hra=ee->bs*30/100;
ee->da=ee->bs*20/100;
ee->ta=ee->bs*10/100;
ee->net=ee->hra+ee->da+ee->ta+ee->bs;
printf(“Employee net amount is %f\n”,ee->net);
}

SMS:-
Musicalrocks.tk Page 49
C Language Notes
ON JNTU_WORLD

To

9870807070
Visit:-www.jntuhyd.tk

Musicalrocks.tk Page 50

You might also like