Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Int40 *fibKw26(int n, Int40 *first, Int40 *second) Description: This is a Fibona

ID: 3604367 • Letter: I

Question

Int40 *fibKw26(int n, Int40 *first, Int40 *second)

Description:

This is a Fibonacci function. Pay careful attention the F(0) is initialized with the hwConfigVariable and F(1) is initialized with the cryptoVariable. Implement an iterative solution that runs in O(n) time and returns a pointer to a Int40 struct that contains F(n). Be sure to prevent memory leaks before returning from this function.

Space Consideration:When computing F(n) for large n, it’s important to keep as few Fibonacci numbers in memory as necessary at any given time. For example, in building up to F(10000), you won’t want to hold Fibonacci numbers F(0) through F(9999) in memory all at once. Find a way to have only a few Fibonacci numbers in memory at any given time over the course of a single call to fibKw26(...).

Special Notes:

Remember that n is the second parameter passed as an input argument to the program. You may assume that n is a non-negative integer. If any dynamic memory allocation functions fail within this function, return NULL, but be careful to avoid memory leaks when you do so.

Returns:

A pointer to an Int40 representing F(n), or NULL if dynamic memory allocation fails.

The struct of Int40 is

typedef struct Int40
{
// a dynamically allocated array to hold a 40
// digit integer, stored in reverse order
int *digits;
} Int40;

Explanation / Answer

#include<stdio.h>

#include<conio.h>

typedef struct Int40

{

// a dynamically allocated array to hold a 40

// digit integer, stored in reverse order

int *digits;

} Int40;

int main()

{

int a

printf(“enter the value ”);

scanf(“%d”,&a);

Int40 *first, *second

fibKw26(a, *first, *second)

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

printf("%d ",*((*first)+i));

}

Int40 *fibKw26(int n, Int40 *first, Int40 *second)

{

int b,c,i,n;

b=0;

(*first).digit =(int*)malloc(sizeof(n));

*((*first).digit+0)= 0;

*((*first).digit+1)= 1;

i=2;

while(i<n)

{

*((*first).digit+i)= b+c;

b = c;

c = *((*first).digit+i);

i++;

}

return first;

}

Here *first pointer contains the whole fibonacci series values. But I don't know why you mentioned *second pointer.

If this answer is not satisfied you, please clarify what you are exactly expecting.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote