All the Notes in one Place. Download our Official App from Google Play.

C Programs Page 3

C Programs Page 3

C Programs Page 3
To view other topics related to Computer. Click Here.

Get two numbers display addition, subtraction, multiplication, division of the numbers

main( )

{

float a,b, ad,sb,mul,div;

printf(“/n enter value of a,b”);

scanf(“%f%f”,&a,&b);

ad=a+b;

sb=a-b;

mul=a*b;

div=a/b;

printf(“/n addition =%f”,ad);

printf(“/n subtraction=%f”,sb);

printf(“/n multiplication =%f”,mul);;

printf(“/n division =%f”, div);

}

Write a program to input a string by using “gets” function and then print it on the screen by using the “puts” function (Gets Function)

main( )

{

charstr[20];

clrscr();

puts(“/n Enter a string ?”);

gets(gets);

puts(“The string is”);

puts(str);

getch();

}

String type variables name &city and print their contents on the screen in left –justified and in right –justified format with field width 30

main( )

{

char name[25]=”wasim javed”;

char city[25]=”D-I-khan”;

clrscr();

printf(“Left – justified /n”);

printf(“%-30s/n”,name);

printf(“%-30s/n”,city);

printf(“Right –justified /n”);

printf(“%-30s/n”,name);

printf(“%-30s/n”,city);

getch();

}

Input the radius of a sphere. Compute its volume and surface area(“Formula for surface area=4 TT r2 and volume=4/3TTr3 and TT=3.1417(Scanf)

main( )

{

float r,v, area;

clrscr();

printf(“Enter radius of sphere?”);

scanf(“%F”,&r);

area=4.0*3.1417*r*r;

v=(4.0/3.0)*3.1417*r*r*r;

printf(“Volume of sphere =%f/n”,v);

printf(“area of sphere=%f/n”,area);

getch();

}

Write a program to declare and initialize the values to variables x,y&z of char type and then print their contents on screen by(Using printf Function)

main( )

{

char x=’r’ ,y=’n’ ,z =’b’;

clrscr ();

printf(“”Data in x=%c/n”,x);

printf(“”Data in y=%c/n”,y);

printf(“”Data in z=%c/n”,z);

}

Write a program to print a message on the screen by using the printf function (Printf Function)

main ( )

{

clrscr();

printf(“The casting vote of the speaker decided the matter”);

printf(“Examination proved a hard pill for me to swallow”);

getch();

}

Write a program in C to assign three values to three integer type variables r,n &b. Add variables r&n and multiply their sum to variable b

main ( )

{

int r,n, b;

clrscr();

r=2;

n=4;

b=6;

b *=r+n

printf(“Result =%d \n”,b);

getch();

}

Post a Comment

Previous Post Next Post