Course objectives


Program to check weather given number is equal to 10 or not (program to illustrate if



Download 0.68 Mb.
Page5/5
Date05.08.2017
Size0.68 Mb.
#26699
1   2   3   4   5

Program to check weather given number is equal to 10 or not (program to illustrate if


else statement)


#include


main()


{


int num;


printf("enter num");


scanf("%d",&num);


if(num==10)


{


printf("equal");


}


else


{


printf("not equal")


}


return 0;


}


Output:


Program to check given number is odd or even




#include


void main()


{


int ival,reaminder;


printf("enter an integer");


scanf("%d",&ival);


rem=ival%2;


if(rem==0)


printf("%d is an even",ival);


else


printf("%d is an odd",ival);


}


Output:


Program to illustrate if else statement




#include


main()


{


int age;


printf("input ur age");


scanf("%d",&age);


if(age>=18)


{


printf("you can vote");


}


else


{


printf(" you are not eligible");


}


}


Output:


Program to illustrate if else statement




#include


main()


{


int grade;


printf("enter grade");


scanf("%d",&grade);


if(grade<=10)


{


printf("you didnt score well");


}


else


{


printf("you done well")'


}


}


Output:


Program to illustrate nested if( program to compare to numbers )




#include


main()


{


int var1,var2;


printf("input the value of var1 and var2");


scanf("%d%d",&var1,&var2);


if(var1!=var2)


{


printf("var1 is not equal to var2");


if(var1>var2)


{


printf("var1 is greater than var2");


}


else


{


printf("var2 is greater than var1");


}


}


else


{


printf("var1 is equal to var2");


}


}


Output:


Program to check username and password enterd by user is correct or not




#include


main()


{


char username;


int psw;


clrscr();


print("username and psw");


scanf("%c %d",&username,&psw);


if(username=='a')


{


if(psw==123)


{


printf("login succesfull");


}


else


{


printf("password is incorrect");


}


}


else


{


printf("username is incorrect");


}


getch();


}


Output:


Program to illustate ternary operator( program to print minimum number )




#include


main()


{


int min,x,y;


printf("enter x and y");


scanf("%d%d",&x,&y);


min=x<=y?x:y;


printf(" n small number is %d",min);


return 0;


}


Output:


Program to print sum of digitd of integers




#include


main()


{


long num,temp,digit,sum=0;


printf("enter the num");


scanf("%ld",&num);


temp=num;


while(num>0)


{


digit=num%10;


sum=sum+digit;


num/=10;


}


printf("given num =%ld\n",temp);


printf("sum of the digits %ld=%ld\n",temp,sum);


}


Output:


Program to check wether given number is palindrome or not




#include


main()


{


long num,rev=0,temp,rem;


printf("enter the num");


scanf("%ld",&num);


temp=num;


while(num>0)


{


rem=num%10;


rev=rev*10+rem;


num/=10;


}


printf("given num =%d",temp);


printf("given num =%d",rev);


if(temp==rev)


printf("num is palindrome");


else


printf("not palindrome");


}


Output:


Program to add three numbers




#include


int main()


{


int a,b,c,sum;


printf("enter the values of a,b and c");


scanf("%d %d %d",&a,&b,&c);


sum=a+b+c;


printf("sum=%d",sum);


return 0;


}


Output:


Program to find area of rectangle




#include


int main()


{


int b,h,area;


printf("enter the values of breadth and height\n");


scanf("%d %d",&b,&h);


area=b*h;


printf("area=%d",area);


return 0;


}


Output:


Program to illustrate initializtion of variable and print the same




#include


main()


{


int a=1,b=2,c=3,d=4,e=5,f=6,g=7,h=8,i=9;


printf("%d,%d,%d\n",a,b,c);


printf("%d,%d,%d\n",d,e,f);


printf("%d,%d,%d\n",g,h,i);


return 0;


}


Output:


Program to illustrate pow() function




#include


main()


{


int a,b,n,e;


printf("enter the values of a,b,n\n");


scanf("%d %d %d",&a,&b,&n);


e=pow(a,10)/pow(b,n)*n;


printf("the answer is=%d",e);


return 0;


}


Output:


Program to swap two numbers without using temp variable




#include


int main()


{


int a=10,b=20;


printf("a=%d,b=%d\n",a,b);


a=a+b;


b=a-b;


a=a-b;


printf("a=%d,b=%d",a,b);


return 0;


}


Output:


Program to swap two numbers without using temp variable




#include


main()


{


int a=10,b=5;printf("a=%d,b=%d\n",a,b);


a=a*b;


b=a/b;


a=a/b;


printf("a=%d,b=%d\n",a,b);


return 0;


}


Output:


Program to swap two numbers with using temp variable




#include


main()


{


int a,b,temp;


printf("enter the value of a,b\n");


scanf("%d %d",&a,&b);


printf("before swapping value of a=%d and b=%d\n",a,b);


temp=a;


a=b;


b=temp;


printf("after swapping value of a=%d\t b=%d\n",a,b);


return 0;


}


Output:


Program to find square root of a given number using builtin function




#include


#include


int main()


{


int a,sqrt_root;


printf("enter the value of a\n");


scanf("%d",&a);


sqrt_root=sqrt(a);


printf("square root of %d=%d\n",a,sqrt_root);


return 0;


}


Output:


Program to illustrate sizeof()




#include


int main()


{


int a,z[10];


float b;


double c;


char d;


printf("Size of int: %d bytes\n",sizeof(a));


printf("Size of float: %d bytes\n",sizeof(b));


printf("Size of double: %d bytes\n",sizeof(c));


printf("Size of char: %d byte\n",sizeof(d));


printf("Size of array: %d byte\n",sizeof(z));


return 0;


}


Output:


Program to demonstrate the working of break statement in C programming




#include


int main ()


{


/* local variable definition */


int a = 10;


/* while loop execution */


while( a < 20 )


{


printf("value of a: %d\n", a);


a++;


if( a > 15)


{


/* terminate the loop using break statement */


break;


}


}


return 0;


}


Output:


C program to demonstrate the working of break statement by terminating a loop, if




user inputs negative number


# include


int main()


{


float num,average,sum;


int i,n;


printf("Maximum no. of inputs\n");


scanf("%d",&n);


for(i=1;i<=n;++i)


{


printf("Enter n%d: ",i);


scanf("%f",&num);


if(num<0.0)


break; //for loop breaks if num<0.0


sum=sum+num;


}


average=sum/(i-1);


printf("Average=%.2f",average);


return 0;


}


Output:


Program to demonstrate the working of continue statement in C programming




#include


main()


{


int x ;


for ( x=0 ; x=100 ; x++)


{


if (x%2) continue;


printf("%d\n" , x);


}


}


Output:


Program to demonstrate the working of continue statement in C programming




# include


int main()


{


int i,num,product;


for(i=1,product=1;i<=4;++i)


{


printf("Enter num%d:",i);


scanf("%d",&num);


if(num==0)


continue; / *In this program, when num equals to zero, it skips the statement


product*=num and continue the loop. */


product*=num;


}


printf("product=%d",product);


return 0;


}


Output:


Program to demonstrate the working of goto statement in C programming




#include


int main ()


{


/* local variable definition */


int a = 10;


/* do loop execution */


LOOP:do


{


if( a == 15)


{


/* skip the iteration */


a = a + 1;


goto LOOP;


}


printf("value of a: %d\n", a);


a++;


}while( a < 20 );


return 0;


}

Output:


ISE Dept., CIT, Gubbi. Page



Download 0.68 Mb.

Share with your friends:
1   2   3   4   5




The database is protected by copyright ©ininet.org 2024
send message

    Main page