C Online Compiler
Example: Fibonacci Series up to 100 in C using For loop
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Fibonacci Series up to 100 in C using For loop #include <stdio.h> // It's the main function of the program int main() { int num; int term_1 = 0, term_2 = 1, next_term = 0; // Step-1 Take input from the User printf("INPUT POSITIVE NUMBER: "); scanf("%d", &num); // Step-2 Displays the first two terms which are always 0 and 1 printf("\nFIBONACCI SERIES: %d, %d, ", term_1, term_2); // Step-3 Use a loop in this range of 1 to N positive numbers and get the next terms for (next_term = term_1 + term_2; next_term <= num; next_term = term_1 + term_2) { printf("%d, ", next_term); term_1 = term_2; term_2 = next_term; } return 0; }
100
Output
Clear
ADVERTISEMENTS