

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


#include <stdio.h>
int sum(int a, int b); int main(void) {
int previous, current, max; int i; int next; printf("Input max number: \n” ); scanf("%d", &max); printf("The first %d Fibonacci numbers:\n", max);
/* calculate and print max Fibonacci numbers */ previous = 0; current = 1; for (i = 0; i < max; ++i) { printf("F(%2d) = %d\n", i, previous); next = sum(previous, current); previous = current; current = next; } return 0; } int sum (int a, int b) { int final; int result = a + b; return result; }
int one = 1; while ( one = 1) one--; sets the variable one to 1, and then sets it alternately to 1 and 0
int i, sum = 0; for (i = 1; i <= 10; ++i); sum += i; Allocate space for i and sum; initialize sum to 0; set i to 1,
increment i from 2 to 11,terminate the for loop; set sum to 11 (0+11).