Write a program to display 1 2 3 5 8 .............nth term.
#include <stdio.h>
#include <conio.h>
void main ( )
{
int n, n1 = 1, n2 = 2, n3 =0, c = 1;
clrscr ( );
printf ("\n\t Enter a number (less than 21).......:"); scanf ("%d", &n);
printf (" %d %d",n1, n2);
do
{
n3 = n1 + n2;
printf ("\t %d", n3);
n1 = n2;
n2 = n3;
c ++;
} while (c <= n );
getch ( );
}
No comments:
Post a Comment