#include<stdio.h>
#include<stdlib.h>
int main()
{
int a,x,y=0,z=1,n;
printf("PROGRAM DERET BILANGAN FIBONACI\n\n");
printf("Ketik jumlah suku = ");
scanf("%d",&n);
for(a=1;a<=n;a++)
{
x=y+z;
z=y;
y=x;
printf("%i ",x);
}
return 0;
}
//cara lain
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a=1,b=1,c,x,jumlah;
printf("Program Fibonacci\n");
printf("Masukkan jumlah bilangan fibonacci = ");
scanf("%d",&jumlah);
printf("%d, ",a);
printf("%d, ",b);
for (x=a;x<=jumlah-2;x++)
{
c=a+b;
printf("%d, ",c);
a=b;
b=c;
}
return 0;
}
//pakai batas
//pakai while
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a=1,b=1,c,batas;
printf("Program Fibonacci\n");
printf("Masukkan jumlah bilangan fibonacci = ");
scanf("%d",&batas);
printf("%d, ",a);
printf("%d, ",b);
c=1;
while(c<=batas)
{
c=a+b;
if(c<=batas)
{
printf("%d, ",c);
a=b;
b=c;
}
else
break;
}
return 0;
}
#include<stdlib.h>
int main()
{
int a,x,y=0,z=1,n;
printf("PROGRAM DERET BILANGAN FIBONACI\n\n");
printf("Ketik jumlah suku = ");
scanf("%d",&n);
for(a=1;a<=n;a++)
{
x=y+z;
z=y;
y=x;
printf("%i ",x);
}
return 0;
}
//cara lain
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a=1,b=1,c,x,jumlah;
printf("Program Fibonacci\n");
printf("Masukkan jumlah bilangan fibonacci = ");
scanf("%d",&jumlah);
printf("%d, ",a);
printf("%d, ",b);
for (x=a;x<=jumlah-2;x++)
{
c=a+b;
printf("%d, ",c);
a=b;
b=c;
}
return 0;
}
//pakai batas
//pakai while
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a=1,b=1,c,batas;
printf("Program Fibonacci\n");
printf("Masukkan jumlah bilangan fibonacci = ");
scanf("%d",&batas);
printf("%d, ",a);
printf("%d, ",b);
c=1;
while(c<=batas)
{
c=a+b;
if(c<=batas)
{
printf("%d, ",c);
a=b;
b=c;
}
else
break;
}
return 0;
}
Comments
Post a Comment