Tuesday 24 December 2013

Program of while loop in “c”

        
Program of while loop in “c”
·       /* to print number from 1 to 5*/
#include<stdio.h>
main()
{
int i;
i=1;
while(i<=5)
{
printf(“%d”,i);
++i;
}
}

·       /* To print even number less than 100 */
#include<stdio.h>
main()
{
int  i=2;
while(i<100)
{
printf(“%d”,i);
i=i+2;
}
}

·       /* To print the sum of digit */
#include<stdio.h>
main()
{
int num,r,s=0;
printf(“enter the digit”);
scanf(“%d”,&num);
while(num>0)
{
r = num%10;
s=s+r;
num=num/10;
}
printf(“sum=%d”,s);
}


·       /* to print  the reverse from of a given number */
#include<stdio.h>
main()
{
int num,r,rev=0;
printf(“enter the number”);
scanf(“%d”,&num);
while(num>0)
{
r=num%10;
rev=rev*10+r;
num=num/10;
}
printf(“reverse num=%d”,rev);
}

·       /* to check the number is pallidrone or not*/
#include<stdio.h>
#include<conio.h>
main()
{
int num,r,rev=0,t;
clrscr();
printf(“enter the number”);
scanf(“%d”,&num);
t=num;
while(num>0)
{
r= num%10;
rev=rev*10+r;
num=num/10;
}
if(t==rev)
printf(“%d is pallidrone”,t);
else
printf(“%d is not pallidrone”,t);
}


·       /*To check the number is armstrong or not */
#include<stdio.h>
main()
{
int num,r,s=0,t;
printf(“enter the number”);
scanf(“%d”,&num);
t=num;
while(num>0)
{
r= num%10;
s=s+r*r*r;
num=num/10;
}
if(t==s)
printf(“%d is armstrong”,t);
else
printf(“%d is not armstrong”,t);

Sunday 22 December 2013

Program of switch & break in c

                            Program of switch & break
/* number of days of a particular month*/
#include<stdio.h>
main()
{
int
mno;
switch(mno)
{
case 1; printf(“31 days”);
case 3;
case 5;
case 7;
case 8;
case 10;
case 12; printf(“31 daya”);break;
case 4;
case 6;
case 9;
case 11;printf(“30 days”);
break;
case 13;printf(“invalide number”);
case 2;printf(“28 or 29 days”);
}
}







Program of else if ladder

                  Program of else if ladder in c
Ø /* TO PRINT NUMBER OF DAYS OF A MONTH*/
#include<stdio.h>
void main()
{
int  m;
printf(“enter the month number”);
scanf(“%d”,&m);
if(m==1 || m==3 || m==5 || m==7 ||m==8 || m==10 || m==12)
printf(“31 days”);
else if(m==4 || m==6 || m==9 || m==11)
printf(“30 days”);
else if(m==2)
printf(“28 or 29 days”);
else
printf(“invalide number”);
}


Program of if else keyword in c

                Program of if else keyword in c
·     /*   program to print greater number */
#include<stdio.h>
 void main()
{
int x,y;
printf(“enter the two number”);
scanf(“%d%d”,&x,&y);
if(x>y)
printf(“%d is greater”,x);
else
printf(“%d is greater”,y);
}

·    /* program to print number is odd or even */
#include<stdio.h>
main()
{
int x;
printf(“enter a number”);
scanf(“%d”,&x);
if(x%2==0)
printf(“%d is even”,x);
else
printf(“%d is odd”,x);
}

·    /* program to print the year is leap or not */
#include<stdio.h>
main()
{
int y;
printf(“enter the year”);
scanf(“%d”,&y);
if(y%4==0)
printf(“%d is leap year”);
else
printf(“%d is not leap year”);
}
                         Or
 /* program to print the year is leap or not */
#include<stdio.h>
main()
{
int y;
printf(“enter the year”);
scanf(“%d”,&y);
if((y%4==0 && y%100!=0) || (y%400==0))
printf(“%d is leap year”,y);
else
printf(“%d is not leap year”,y);
}






Friday 20 December 2013

Program of nested if in c











                   Program of nested if in c
·       /* Program  to print smallest number among three number*/
#include<stdio.h>
main()
{
int  x,y,z;
printf(“enter three number”);
scanf(“%d%d%d”,&x,&y,&z);
if(x<y)
{
          If(x<z)
          printf(“%d is smallest number”,x);
          else
          printf(“%dis smallest number”,z);
}
else
{
          If(y<z)
          printf(“%d is smallest”,y);
          else
          printf(“%d is smallest”,z);
}
}



Program of simple if keyword in c language










    Program of  simple if keyword in c language
·       /* program to display the number is < 25 */
#include<stdio.h>
 void main()
{
int n;
printf(“enter the number ”);
scanf(“%d”,&n);
If(n<25)
{
printf(“number is %d”,n);
}




Simple program of c

                        

                               Simple program of c
·       / * Program to display message on the screen */
#include<stdio.h>
 void main()
{
 printf(“Welcome to the Word of c”);
}

·        /* program to print the sum of two number */
#include<stdio.h>
 void main()
{
 int x, y, s;
 printf(“enter the two number”);
 scanf(“%d%d”,&x,&y);
 s=x+y;
 printf(“sum=%d”,s);
}
·       /* program to print the product of three number */
#include<stdio.h>
 void main()
{
 int a,b,c,p;
 printf(“enter the three number”);
 scanf(“%d%d%d”,&a,&,b,&c);
p=a*b*c;
printf(“product=%d”,p);
}

·       /* program to print area of rectangle */
#include<stdio.h>
 void main()
{
int l,b,a;
printf(“enter the length and breadth of rectangel”);
scanf(“%d%d”,&l,&b);
a=l*b;
printf(“area of rectangle is =%d”,a);
}

·       /* program to print circumference of circle */
#include<stdio.h>
 void main()
{
int r;
float c;
printf(“enter the radius of circle”);
scanf(“%d”,&r);
c=3.14*r*r;
printf(“circumference of circle is %f”,c);
}

·       /* program to interchange or swap of two number */
#include<stdio.h>
void main()
{
Int x,y,t;
printf(“enter two number”);
scanf(“%d%d”,&x,&y);
printf(“before interchange \n”);
printf(“x=%d\n y= %d”,x,y);
t=x;
x=y;
y=t;
printf(“after inter change\n”);
printf(“x=%d\n y=%d\n”x,y);
}