
- Learn C By Examples Time
- Learn C by Examples - Home
- C Examples - Simple Programs
- C Examples - Loops/Iterations
- C Examples - Patterns
- C Examples - Arrays
- C Examples - Strings
- C Examples - Mathematics
- C Examples - Linked List
- C Programming Useful Resources
- Learn C By Examples - Quick Guide
- Learn C By Examples - Resources
- Learn C By Examples - Discussion
Fibonacci Series Program In C
Finding that a given number is even or odd, is a classic program. We shall learn the use of conditional statement if-else
in C.
Algorithm
Algorithm of this program is very easy −
START Step 1 → Take integer variable A Step 2 → Assign value to the variable Step 3 → Perform A modulo 2 and check result if output is 0 Step 4 → If true print A is even Step 5 → If false print A is odd STOP
Flow Diagram
We can draw a flow diagram for this program as given below −

Pseudocode
procedure even_odd() IF (number modulo 2) equals to 0 PRINT number is even ELSE PRINT number is odd END IF end procedure
Implementation
Implementation of this algorithm is given below −
#include <stdio.h> int main() { int a,b,c,i,n; printf("Enter n value to generate fibonacci series : "); scanf("%d",&n); a=b=1; printf("%d %d ",a,b); for(i=1;i<=n-2;i++) { c=a+b; printf("%d ",c); a=b; b=c; } return 0; }
Output
Output of the program should be −
24 is even 31 is odd
Advertisements