Tuesday 7 January 2014

"for" loop in c

/* To print the fibonacci series*/
#include<stdio.h>
void main()
{
int x=1,y=0,z,t,i;
printf("enter number of terms");
scanf("%d",&t);
for(i=1; i<=t; ++i)
{
z=x+y;
x=y;
y=z;
}
}

/* program to check the given number is dracula or not*/
#include<stdio.h>
void main()
{
int num,r,r1,s=0;
printf("enter the number");
scanf("%d",&num);
r=num%10;
num=num/10;
for( ; num>0; num=num/10)
{
r1=num%10;
s=s+r1;
}
if(r==s)
printf("number is dracula");
else
printf("number is not dracula");
}

No comments:

Post a Comment