// Program by Akash Tripathi (@proakash256)
import java.util.Scanner;
public class Fibonacci_even_Sum
{
public static void main(String args[])
{
int a = 0 , b = 1 , sum = a + b , s = 0 , n;
Scanner sc = new Scanner(System.in);
System.out.printf("Enter the number of terms
till which you want to
print the sum : ");
n = sc.nextInt();
sc.close();
for(int i = 1; i <= n; i = i + 1)
{
if(sum >= 4000000)
break;
if(sum % 2 == 0)
s = s + sum;
a = b;
b = sum;
sum = a + b;
}
System.out.printf("%d" , s);
}
}
Comments
Post a Comment