Algoritma
Deklarasi
n : integer
i : integer
a[1..50]: integer
Deskripsi
Read n
for i <- 0 to n do
if (i<2)then
a[i]<-1
else
a[ i ] <- a[ i - 2 ] + a[ i - 1 ]
end if
end for
For i <- 0 to n do
Write a[ i ]
end for
end
Deklarasi
n : integer
i : integer
a[1..50]: integer
Deskripsi
Read n
for i <- 0 to n do
if (i<2)then
a[i]<-1
else
a[ i ] <- a[ i - 2 ] + a[ i - 1 ]
end if
end for
For i <- 0 to n do
Write a[ i ]
end for
end
C++ nya :
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int bil,a,b,c,d;
cout<<"DERET FIBONACI"<<endl;
cout<<endl;
cout<<"Masukkan banyaknya bilangan = ";cin>>bil;
a=0;b=1;
cout<<"1";
for(d=1;d<=bil-1;d++){
c=a+b;
a=b;b=c;
cout<<" "<<c;
}
cout<<endl;cout<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int bil,a,b,c,d;
cout<<"DERET FIBONACI"<<endl;
cout<<endl;
cout<<"Masukkan banyaknya bilangan = ";cin>>bil;
a=0;b=1;
cout<<"1";
for(d=1;d<=bil-1;d++){
c=a+b;
a=b;b=c;
cout<<" "<<c;
}
cout<<endl;cout<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
#Screenshot Dev C++ :
#Screenshot flowchart :
Tidak ada komentar:
Posting Komentar