Tuesday, 19 November 2013

C-Program to Generate the series 0 2 1 3 1 5 2 7 3 11 5 13 8 17 13 19 21 23 34 29. . . . .

#include<stdio.h>
main ()
{
int j=0,i=2,n,r,p[100]={0},f[100]={0},a=0,b=1,c;
printf("enter the Number of terms needed\t");
scanf("%d",&n);
for(r=1;r<=(2*n);r++)
{
for(i=2;i<r;i++)
{
if(r%i==0)
break;
}
if(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