C Online Compiler
Example: Fibonacci Series up to 100 in C using Function
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Fibonacci Series up to 100 in C using Function #include <stdio.h> // Function to generate the Fibonacci series int generate_fibonacci(int num) { int term_1 = 0, term_2 = 1, next_term = 0; printf("%d, %d, ", term_1, term_2); // Prin the initial terms of fibonacci series next_term = term_1 + term_2; while (next_term <= num) { printf("%d, ", next_term); term_1 = term_2; term_2 = next_term; next_term = term_1 + term_2; } } // It's the main function of the program int main() { int num; // Step-1 Take input from the User printf("INPUT POSITIVE NUMBER: "); scanf("%d", &num); // Step-2 Call the generate_fibonacci() function to generate the fibonacci series printf("\nFIBONACCI SERIES: "); generate_fibonacci(num); return 0; }
60
Output
Clear
ADVERTISEMENTS