C Online Compiler
Example: Fibonacci Series up to 100 in C using Do-while loop
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Fibonacci Series up to 100 in C using Do-while 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 next_term = term_1 + term_2; do { printf("%d, ", next_term); term_1 = term_2; term_2 = next_term; next_term = term_1 + term_2; } while (next_term <= num); return 0; }
200
Output
Clear
ADVERTISEMENTS