Skip to content

pavithrakuricheti534/fibonacci-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

fibonacci-

/Lab 2.2)Write a program to print sum of even numbers in Fibonacci sequence/

import java.util.Scanner;

class FibonacciSum

{

public static void main(String[] args)	{

	int n,sum=0,f,temp,i,x=0,y=1;

	Scanner s=new Scanner(System.in);

	System.out.print("Enter a number:");

	n=s.nextInt();

	for(i=0;i<=n;i++)

	{

		temp=x;

		f=x+y;

		x=y;

		y=f;

		if(temp%2==0)

		{

			sum=sum+temp;

		}

	}

System.out.println("sum of even numbers in Fibonacci sequence"+sum);

	

}

}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published