Skip to content

Commit 3bf7699

Browse files
Even Fibonacci Number
A program that prompts the user to input the range up to which they want to display the even Fibonacci number and finds it's sum.
1 parent 8ff007e commit 3bf7699

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Even Fibonacci numbers

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include<stdio.h>
2+
void main()
3+
{
4+
int i;//loop counter
5+
int n;//max value
6+
int t1=1;//First term
7+
int t2=1;//Second term
8+
int nextTerm;//Next term
9+
int sum=0;//Summation of total even Fibonacci number
10+
int count=0;//counter to count the number of even Fibonacci numbers
11+
printf("Enter the max value up to which you want to print the values: ");
12+
scanf("%d",&n);
13+
printf("The listed even Fibonacci number are: ");
14+
printf("\nSlno.\t\tFibonacci number");
15+
for(i=1;i<=n;i++)
16+
{
17+
if(t1>=1 && t1<=n)
18+
{
19+
nextTerm=t1+t2;
20+
t1=t2;
21+
t2=nextTerm;
22+
23+
if(t1%2==0 && t1<=n)
24+
{
25+
sum=sum+t1;
26+
count++;
27+
printf("\n %d\t\t\t%d",count,t1);
28+
}
29+
}
30+
31+
}
32+
printf("\n\nThe required sum of the total even Fibonacci number is: %u\n\n\n",sum);
33+
34+
}

0 commit comments

Comments
 (0)