Fibonacci Series in C Program
#include <stdio.h>
main()
{
int a=0, b=1,no,counter,c;
printf("PROGRAM TO FIND THE FIBONACCI SERIES UP TO N NO. IN SERIES");
printf("\n");
printf("\nENTER LENGTH OF SERIES (N) : ");
scanf("%d",&no);
printf("\nFIBONACCI SERIES");
printf("\n\t%d %d",a,b);
//LOOP WILL RUN FOR 2 TIME LESS IN SERIES AS THESE WAS PRINTED IN ADVANCE
for(counter = 1; counter <= no-2; counter++)
{
c=a + b;
printf(" %d",c);
a=b;
b=c;
}
printf("\n");
getch();
}
#include <stdio.h>
main()
{
int a=0, b=1,no,counter,c;
printf("PROGRAM TO FIND THE FIBONACCI SERIES UP TO N NO. IN SERIES");
printf("\n");
printf("\nENTER LENGTH OF SERIES (N) : ");
scanf("%d",&no);
printf("\nFIBONACCI SERIES");
printf("\n\t%d %d",a,b);
//LOOP WILL RUN FOR 2 TIME LESS IN SERIES AS THESE WAS PRINTED IN ADVANCE
for(counter = 1; counter <= no-2; counter++)
{
c=a + b;
printf(" %d",c);
a=b;
b=c;
}
printf("\n");
getch();
}
No comments:
Post a Comment