WAP in C to Print the Fibonacci series 1, 1, 2, 3, 5, 8, 13..N

The Program in C that Prints the Fibonnicci series1, 1, 2, 3, 5, 8, 13..N is given below:

``````#include <stdio.h>

int main() {
int n, a = 0, b = 1, c;
printf("Enter the value of N: ");
scanf("%d", &n);

printf("Fibonacci series: ");
for (int i = 1; i <= n; i++) {
if (i == 1) {
printf("%d, ", a);
continue;
}
if (i == 2) {
printf("%d, ", b);
continue;
}
c = a + b;
a = b;
b = c;
printf("%d, ", c);
}
return 0;
}
``````

Output:

Enter the value of N: 45
Fibonacci series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733,

Pro-Tips💡

This program prompts the user to enter an integer N, then uses a for loop to print the first N numbers of the Fibonacci series.

The Fibonacci series is a series of numbers in which each number is the sum of the two preceding ones, usually starting with 0 and 1.

The program initializes two variables `a` and `b` to 0 and 1 respectively, which are the first two numbers of the series.

In the loop, it uses an if statement to check if the current iteration is the first or second iteration, if it is, it prints the initial values of a and b respectively,

otherwise it calculates the next number in the series (c=a+b), updates the value of a and b and prints the value of c. This way the Fibonacci series from 1 to N will be printed.

Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

C# Program to Delete Element at Desired position From Array

The Program in C# Program to Delete Element at Desired position From Array is given below: Output: Hello Codeauri Family, enter the number of elements in the array:4Enter…

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X