You are on page 1of 8

(1): Exchange the values of two variables (using third variable) by taking input #include<stdio.

h> main( ) { int a,b,c; clrscr( ); printf("enter value of a="); scanf("%d",&a); printf("enter value of b="); scanf("%d",&b); c=a; a=b; b=c; printf("\nvalue of a=%d",a); printf("\n\nvalue of b=%d",b); getch( ); } (2): Exchange the values of two variables (without using third variable) by taking input #include<stdio.h> main( ) { int a,b; clrscr( ); printf("enter value of a="); scanf("%d",&a); printf("enter value of b="); scanf("%d",&b); a=a-b; b=a+b; a=b-a; printf("\nvalue of a=%d",a); printf("\n\nvalue of b=%d",b); getch( ); } (3): Take the input of an integer type value for any variable & print the following: a. Decimal Format of the value b. ASCII Format of the value c. Hexadecimal Format of the value d. Octal Format of the value

#include<stdio.h> main( ) { int num; clrscr( ); printf("enter any value of num="); scanf("%d",&num); printf("\ndecimal value of num=%d",num); printf("\nASCII value of num is=%c", num); printf("\noctal value of num is=%o",num); printf("\nhexadecimal value of num is=%x",num); getch( ); } (4): Write a program to calculate the Area of a Triangle where s = a+b+c/2 & Area = sqrt (s*(s-a)*(s-b)*(s-c)) #include<stdio.h> #include<math.h> main ( ) { float a,b,c,s,area; printf("enter the value for a,b,c="); scanf("%f %f %f", &a,&b,&c); s=(a+b+c)/2; area=sqrt(s*(s-a)*(s-b)*(s-c)); printf("value of area=%f",area); getch(); } (5): Take an input for a temperature & converts it into Fahrenheit & Celsius #include<stdio.h> #include<math.h> main( ) { float temp, celcius, farenhite; clrscr ( ); printf("enter the value of temp="); scanf("%f", &temp); celcius=5*(temp-32)/9; farenhite=9*temp/5+32; printf("temp in celcius=%f",celcius); printf("temp in farenhite=%f",farenhite); getch(

(6): Take an input of a real number & separate it into integer & decimal parts #include<stdio.h> main() { float b,num; int a; clrscr(); printf("enter any real num="); scanf("%f",&num); a=(int)num; b=num-a; printf("\ninteger part is=%d",a); printf("\n\ndecimal part is=%f",b); getch(); } (7): Take an input of a three digit number & separate it into three parts #include<stdio.h> #include<math.h> main( ) { int num,a,b,c,d; clrscr( ); printf("enter any three digit number="); scanf("%d",&num); a=num/100; b=num%100; c=b/10; d=b%10; printf("\nfirst digit is=%d",a); printf("\nsecond digit is=%d",c); printf("\nthird digit is=%d",d); getch( ); } (8): Take an input of any character (alphabet) & print: a. Character in upper case b. Character in lower case c. Character is a digit d. Wrong character entered #include<stdio.h> main( )

{ char ch; clrscr( ); printf("enter any character="); scanf("%c",&ch); if ((ch>=65)&&(ch<=90)) { printf("character in lower case=%c",ch+32); } else if((ch>=97)&&(ch<=122)) { printf("character in upper case=%c",ch-32); } else if((ch>=47)&&(ch<=57)) { printf("character is a digit"); } else { printf("character is invalid"); } getch( ); } (10): Take an input of two integers & an operator (>, <, ==,! =) & show the output as True or False after evaluating the operation #include<stdio.h> #include<conio.h> main( ) { int a,b; char ch; clrscr(); printf("enter any character="); scanf("%c", &ch); printf("enter any value for a="); scanf("%d", &a); printf("enter any value for b="); scanf("%d", &b); if(ch=='>') { if(a>b) { printf("true"); }

else { printf("false"); } } else if(ch=='<') { if(a<b) { printf("true"); } else { printf("false"); } } else if(ch=='=') { if(a==b) { printf("true"); } else { printf("false"); } } else if(ch=='!') { if(a!=b) { printf("true"); } else { printf("false"); } } getch( ); } (11): Take an input of a character & checks that whether it is a vowel or consonant #include<stdio.h> #include<conio.h> main()

{ char ch; clrscr(); printf("enter the char="); scanf("%c",&ch); switch(ch) { case 'a': printf("vowel"); break; case 'e': printf("vowel"); break; case 'i': printf("vowel"); break; case 'o': printf("vowel"); break; case 'u': printf("vowel"); break; default: printf("consonant"); } getch(); } (12): Take an input of a number & find out either the number is odd or even #include<stdio.h> main( ) { int num; clrscr( ); printf("enter any num="); scanf("%d",&num); if (num%2==0) { printf("num is even"); } else { printf("num is odd"); }

getch( ); } (14): Take an input of a number & calculate the factorial for that number # include<stdio.h> main( ) { int n , c=1; clrscr( ); printf("\nenter any digit="); scanf("%d",&n); while (n>=1) { c=c*n; n=n -1; } printf("factorial is equal=%d",c); getch( ); }

(15):

#include<stdio.h> #include<math.h> main() { int num,c,j; c=1; clrscr(); printf("enter any integer="); scanf("%d" ,&num); for(;num>=1;) { c=c+num; num--; } j=c-(num+1); printf("=%d",j);

getch(); return(0); (16): sum of the series #include<stdio.h> main() { int b,c,a=1; printf("digit="); scanf("%d",&b); for(b;b>=1;b--) { a=a+b; } c=a-1; printf("sum=%d",c); getch(); } (17): Table #include<stdio.h> main() { int a,m,n; clrscr(); printf("enter any digit="); scanf("%d",&a); for(n=1;n<=10;n++); { m=a*n; printf("\n%d*%d=%d",a,n,m); } getch(); }

You might also like