Wednesday, 28 August 2013

Generate a sequence of numbers such that every number in the sequence is the sum of the previous three numbers. The first three numbers are 0,0,1.

#include<stdio.h>
void main()
{
int n,a=0,b=0,c=1,d;
printf("Enter how many terms in series : ");
scanf("%d",&n);
printf("\n %d %d %d ",a,b,c);
while(n>0)
{
d=a+b+c;
a=b;
b=c;
c=d;
printf("%d ",d);
--n;
}
}

No comments:

Post a Comment