C Program to Print Fibonacci Series up to N Numbers Using Loops and if statement

C Program to Print Fibonacci Series up to N Numbers Using Loops and if statement

Tech Knowledge C Program to Print Fibonacci Series up to N Numbers Using Loops and if statement
C Program to Print Fibonacci Series up to N Numbers Using Loops and if statement


*C Program to Print Fibonacci Series up to N Numbers Using For Loop


  1.  
  2. //C Program to Print Fibonacci Series upto N Numbers Using For Loop

  3. #include <stdio.h>
  4. int main() {
  5.     int i, n, Number1 = 0, Number2 = 1, next_Number;
  6.     printf("Enter the number to print first N Fibonacci Series:- ");
  7.     scanf("%d", &n);
  8.     printf("Fibonacci Series As Follow :- ");

  9.     for (i = 1; i <= n; i++) {
  10.         printf("%d, ", Number1);
  11.        next_Number = Number1 + Number2;
  12.         Number1 = Number2;
  13.         Number2 = next_Number;
  14.     }

  15.     return 0;
  16. }


Output

Test-1
Enter the number to print first N Fibonacci Series:- 10
Fibonacci Series As Follow :- 0, 1, 1, 2, 3, 5, 8, 13, 21, 34,

Test-2
Enter the number to print first N Fibonacci Series:- 20
Fibonacci Series As Follow : 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181,

*C Program to Print Fibonacci Series up to N Numbers Using while Loop

  1. //C Program to Print / Display Fibonacci Series up to N Number Using While Loop

  2. #include <stdio.h>
  3. int main() {
  4.     int i=1, n, Number1 = 0, Number2 = 1, next_Number;
  5.     printf("Enter the number to print first N Fibonacci Series:- ");
  6.     scanf("%d", &n);
  7.     printf("Fibonacci Series As Follow :- ");

  8.     while (i <= n)
  9.  {
  10.         printf("%d, ", Number1);
  11.        next_Number = Number1 + Number2;

  12.         Number1 = Number2;
  13.         Number2 = next_Number;
  14.          i++;
  15.     }

  16.     return 0;

  17. }


Output

Test-1
Enter the number to print first N Fibonacci Series:- 10
Fibonacci Series As Follow :- 0, 1, 1, 2, 3, 5, 8, 13, 21, 34,

Test-2
Enter the number to print first N Fibonacci Series:- 20
Fibonacci Series As Follow : 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181,

*C Program to Print Fibonacci Series up to N Numbers Using do-while Loop

  1.  
  2. //C Program to Print / Display Fibonacci Series up to N Number Using do-While Loop

  3. #include <stdio.h>
  4. int main() {
  5.     int i=1, n, Number1 = 0, Number2 = 1, next_Number;
  6.     printf("Enter the number to print first N Fibonacci Series:- ");
  7.     scanf("%d", &n);
  8.     printf("Fibonacci Series As Follow :- ");

  9.     do
  10.  {
  11.         printf("%d, ", Number1);
  12.        next_Number = Number1 + Number2;

  13.         Number1 = Number2;
  14.         Number2 = next_Number;
  15.          i++;
  16.     }while (i <= n);

  17.     return 0;
  18. }


Output

Test-1
Enter the number to print first N Fibonacci Series:- 10
Fibonacci Series As Follow :- 0, 1, 1, 2, 3, 5, 8, 13, 21, 34,

Test-2
Enter the number to print first N Fibonacci Series:- 20
Fibonacci Series As Follow : 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181,


*C Program to Print / Display Fibonacci Series upto N Number using if statement


  1. //C Program to Print / Display Fibonacci Series upto N Number using if statement

  2. #include <stdio.h>
  3. int main() {
  4.     int i=1, n, Number1 = 0, Number2 = 1, next_Number;
  5.     printf("Enter the number to print first N Fibonacci Series:- ");
  6.     scanf("%d", &n);
  7.     printf("Fibonacci Series As Follow :- ");

  8. Restart:
  9.     if (i <= n)
  10.  {
  11.         printf("%d, ", Number1);
  12.        next_Number = Number1 + Number2;

  13.         Number1 = Number2;
  14.         Number2 = next_Number;
  15.          i++;
  16. goto Restart;
  17.     }

  18.     return 0;
  19. }


Output

Test-1
Enter the number to print first N Fibonacci Series:- 10
Fibonacci Series As Follow :- 0, 1, 1, 2, 3, 5, 8, 13, 21, 34,

Test-2
Enter the number to print first N Fibonacci Series:- 20
Fibonacci Series As Follow : 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181,

Comments