From a57c018488724ec5ca87e411144db20748946ae0 Mon Sep 17 00:00:00 2001 From: suraj-singh12 <71935307+suraj-singh12@users.noreply.github.com> Date: Thu, 11 Feb 2021 01:19:08 +0530 Subject: [PATCH] Update and rename even fibonacci series sum MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Code refactored Comments added for more clarity Included required headers, so code ready to run File renamed according to the task code is doing Signed-off-by: – --- Even Fibonacci numbers sum.c | 29 +++++++++++++++++++++++++++++ Even Fibonacci numbers.c | 15 --------------- 2 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 Even Fibonacci numbers sum.c delete mode 100644 Even Fibonacci numbers.c diff --git a/Even Fibonacci numbers sum.c b/Even Fibonacci numbers sum.c new file mode 100644 index 0000000..0069fe8 --- /dev/null +++ b/Even Fibonacci numbers sum.c @@ -0,0 +1,29 @@ +/* Program to calculate sum of even fibonacci series numbers upto a limit (entered by user) + * fibonacci series for limit 13: + * 1 1 2 3 5 8 + * even sum = 2 + 8 = 10 + * */ + +#include +int main() { + int first=1, next=1, sum, limit; + int evensum = 0; + + printf("Enter Limit: "); + scanf("%d",&limit); + + while(true) { + //logic for generating fibonacci series + sum = first + next; + first = next; + next = sum; + + if(sum >= limit) + break; + + if(sum%2==0) + evensum += sum; + } + printf("Even sum = %d \n",evensum); + return 0; +} diff --git a/Even Fibonacci numbers.c b/Even Fibonacci numbers.c deleted file mode 100644 index 97ddfb8..0000000 --- a/Even Fibonacci numbers.c +++ /dev/null @@ -1,15 +0,0 @@ -int main() { - int x=1,y=2,sum,limit; - int evensum=2; - printf("Enter Limit: "); - scanf("%d",&limit); - while( (x+y)