Tuesday, 19 November 2013

C-Program to Generate series of 0 2 1 3 1 5 2 8 3 12 5 17 8 23 13 30 21 . . . . .

#include<stdio.h>
main ()
{
int j=0,i=2,n,r=2,p[100]={0},f[100]={0},a=0,b=1,c;
printf("enter the Number of terms needed\t");
scanf("%d",&n);
for(i=0;i<n;i++)
{
r=r+i;
p[j]=r;
j++;
}  
for(i=0;i<n;i++)
{
if(i<=1)
c=i;
else
{
c=a+b;
a=b;
b=c;
}
f[i]=c;
}
printf("The elements are \t");
if(n%2==0)
for(i=0;i<(n/2);i++)
printf("%d\t%d\t",f[i],p[i]);
  else
{
for(i=0;i<(n/2);i++)
printf("%d\t%d\t",f[i],p[i]);    
printf("%d\t",f[i]);
}
}



sakoncepts.blogspot.com
output

No comments:

Post a Comment