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”);
}