Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Linux and C. I already have a code for the first one but not the Overflow cases. The code is below Code I have: Like

Linux and C. I already have a code for the first one but not the Overflow cases. The code is below

image text in transcribedimage text in transcribed

Code I have: Like I said everything is working but not the overflow case.

#include

int fibo_negative(int N) /*this function compute for negative N*/

{

int past = 1,i; /*past variable contain number which is 2 step beyond */

int present = 0; /*present variable contain number which is 1 step beyond */

int next; /*next variable compute the present number that we are interested in*/

for(i=0;i

{

next = past-present;

past = present;

present = next;

}

return next;

}

int fibo_positive(int N) /*this function compute for positive N*/

{

int past = 0,i; //past variable contain number which is 2 step beyond

int present = 1; //present variable contain number which is 1 step beyond

int next; /ext variable compute the present number that we are interested in

for(i=0;i

{

next = past+present;

past = present;

present = next;

}

return next;

}

int main()

{

int N;

printf(" Enter a number:"); //Prompt the user

scanf("%d",&N);

if(N

printf("F(%d) is %d ",N,fibo_negative(N)); /*If N is negative then call fibo_negative */

else

printf("F(%d) is %d ",N,fibo_positive(N)); /*If N is positive then call fibo_positive */

return 0;

}

2. Define the extended Fibonacci numbers, F as follows: Fn = Fn-l + Fn-2 if n > 1 F-Fn+2-Fn+ if n <>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sybase Database Administrators Handbook

Authors: Brian Hitchcock

1st Edition

0133574776, 978-0133574777

More Books

Students also viewed these Databases questions