C Programming Code Examples C > Mathematics Code Examples Program to Generate Fibonacci Sequence Up to a Certain Number Program to Generate Fibonacci Sequence Up to a Certain Number The Fibonacci sequence is a series where the next term is the sum of pervious two terms. The first two terms of the Fibonacci sequence is 0 followed by 1. The Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21 #include <stdio.h> int main() { int j1 = 0, j2 = 1, nextTerm = 0, n; printf("Enter a positive number: "); scanf("%d", &n); // displays the first two terms which is always 0 and 1 printf("Fibonacci Series: %d, %d, ", j1, j2); nextTerm = j1 + j2; while(nextTerm <= n) { printf("%d, ",nextTerm); j1 = j2; j2 = nextTerm; nextTerm = j1 + j2; } return 0; }