Home > Computer Programming > Bilangan Fibionaci dengan abap

Bilangan Fibionaci dengan abap


tadi saya baru saja di test untuk membuat sebuah bilangan fibionaci.

bilangan fibionaci adalah bilangan yang berurutan sesuai dengan bilangan yang sebelumnya

yaitu: 1.1.2.3.5.8.13.21.34

dikarena kan suatu sebab dan lain hal, hasil test yang saya kerjakan salah.

namun setelah sampai rumah, ternyata saya bisa mengerjakannya (padahal mikirnya pas di jalan doang)

jawaban logiknya adalah

int a = 0, b=1, c=0;
print b;
for int i = 1 to 9
c = a + b;
print c;
a = b;
b = c;
next i

test logiknya adalah di bawah ini:

step number code a b c i print out
1 int a = 0, b=1, c=0; 0 1 0
2 print b; 0 1 0 1
3 for int i = 1 to 9 0 1 0 1
4 c = a + b; 0 1 1 1
5 print c; 0 1 1 1 1
6 a = b; 1 1 1 1
7 b = c; 1 1 1 1
8 I=2 from loop 1 1 1 2
9 c = a + b; 1 1 2 2
10 print c; 1 1 2 2 2
11 a = b; 1 1 2 2
12 b = c; 1 2 2 2
13 I=3 from loop 1 2 2 3
14 c = a + b; 1 2 3 3
15 print c; 1 2 3 3 3
16 a = b; 2 2 3 3
17 b = c; 2 3 3 3
18 I=4 from loop 2 3 3 4
19 c = a + b; 2 3 5 4
20 print c; 2 3 5 4 5
21 a = b; 3 3 5 4
22 b = c; 3 5 5 4
23 I=5 from loop 3 5 5 5
24 c = a + b; 3 5 8 5
25 print c; 3 5 8 5 8
26 a = b; 5 5 8 5
27 b = c; 5 8 8 5
28 I=6 from loop 5 8 8 6
29 c = a + b; 5 8 13 6
30 print c; 5 8 13 6 13
31 a = b; 8 8 13 6
32 b = c; 8 13 13 6
33 I=7 from loop 8 13 13 7
34 c = a + b; 8 13 21 7
35 print c; 8 13 21 7 21
36 a = b; 13 13 21 7
37 b = c; 13 21 21 7
38 I=8 from loop 13 21 21 8
39 c = a + b; 13 21 34 8
40 print c; 13 21 34 8 34
41 a = b; 21 21 34 8
42 b = c; 21 34 34 8

hasil print outnya adalah:

1.1.2.3.5.8.13.21.34

bener kan….

nah sekarang kita aplikasikan di programnya

versi Abap nya nyusul yaa

menggunakan turbo c sebagai compiler, language c

/*
	test bilangan fibionaci
	date 28 jan 2010
	by ronny fch
	compiler turbo c
	language c
*/
#include
#include
void main()
{
	int a = 0, b = 1, c = 0, d=0;
	clrscr();
	cout << "Bilangan Fibionaci\n";
	cout << d;
	cout << "\n1";
	for(int i=0; i<d-1; i++)
	{
		c = a + b;
		cout << "," << c;
		a = b;
		b = c;
	}
	cout << "\nPress anykey to exit";
	getch();
}
Categories: Computer Programming
  1. No comments yet.
  1. No trackbacks yet.

Please kindly Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: