-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.vc
More file actions
45 lines (39 loc) · 1.06 KB
/
example.vc
File metadata and controls
45 lines (39 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* fibo.c -- It prints out the first N Fibonacci */
void main() {
int n; /* The number of fibonacci numbers we will print */
int i; /* The index of fibonacci number to be printed next */
int current; /* The value of the (i)th fibonacci number */
int next; /* The value of the (i+1)th fibonacci number */
int twoaway; /* The value of the (i+2)th fibonacci number */
putString("How many Fibonacci numbers do you want to compute? ");
n = getInt();
if (n<=0)
putString("The number should be positive.\n");
else {
putString("\n\n\tI \t Fibonacci(I) \n\t=====================\n");
next = current = 1;
for (i=1; i<=n; i=i+1) {
putString("\t");
putInt(i);
putString("\t");
putIntLn(current);
twoaway = current+next;
current = next;
next = twoaway;
}
}
}
/* The output from a run of this program was:
How many Fibonacci numbers do you want to compute? 9
I Fibonacci(I)
=====================
1 1
2 1
3 2
4 3
5 5
6 8
7 13
8 21
9 34
*/