Write a function to construct the image shown below.
1
1 1
1 1 2
1 1 2 3
1 1 2 3 5
1 1 2 3 5 8
#include <stdio.h>
#include <conio.h>
void fibo ( int );
void main ( )
{
int i;
clrscr ( );
printf("\n\n\n");
for ( i = 1; i <= 6; i++ )
{
printf("\n\n");
fibo(i);
}
getch ( );
}
void fibo ( int n )
{
int p = 1, c = 1, f, i = 3;
if ( n == 1 )
{
printf("\t\t\t %d",p);
}
else
{
printf("\t\t\t %d %d",p,c);
}
f = p + c;
while ( i <= n )
{
printf(" %d",f);
p = c;
c = f;
f = p + c;
i++;
}
}
Click here to contact us
1
1 1
1 1 2
1 1 2 3
1 1 2 3 5
1 1 2 3 5 8
#include <stdio.h>
#include <conio.h>
void fibo ( int );
void main ( )
{
int i;
clrscr ( );
printf("\n\n\n");
for ( i = 1; i <= 6; i++ )
{
printf("\n\n");
fibo(i);
}
getch ( );
}
void fibo ( int n )
{
int p = 1, c = 1, f, i = 3;
if ( n == 1 )
{
printf("\t\t\t %d",p);
}
else
{
printf("\t\t\t %d %d",p,c);
}
f = p + c;
while ( i <= n )
{
printf(" %d",f);
p = c;
c = f;
f = p + c;
i++;
}
}
Click here to contact us
No comments:
Post a Comment