Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

im having trouble running my c code #include bigint.h BIGINT bigint(char *p) { BIGINT bn = {0}; if (p == NULL) return bn; else if

im having trouble running my c code

#include "bigint.h"

BIGINT bigint(char *p) {

BIGINT bn = {0};

if (p == NULL)

return bn;

else if (!(*p >= '0' && *p <= '9')) {// not begin with digits

return bn;

}

else if (*p == '0' && *(p+1) == '\0') {// just "0"

insert_end(&bn.start, &bn.end, new_node(*p -'0'));

return bn;

}

else {

while (*p) {

if (*p >= '0' && *p <= '9' ){

insert_end(&bn.start, &bn.end, new_node(*p -'0'));

} else {

clean_bigint(&bn);

break;

}

p++;

}

return bn;

}

}

void display_bigint(BIGINT bignumber) {

NODE *ptr = bignumber.start;

while ( ptr != NULL) {

printf("%d", ptr->data);

ptr = ptr->next;

}

}

void clean_bigint(BIGINT *bignumberp) {

clean(&bignumberp->start, &bignumberp->end);

}

BIGINT add(BIGINT op1, BIGINT op2) {

BIGINT sum = bigint(NULL);

NODE *p1 = op1.end;

NODE *p2 = op2.end;

int c = 0, a, b, s;

while (p1 || p2) {

a = 0; b = 0;

if(p1) {

a = p1->data;

p1 = p1->prev;

}

if(p2) {

a = p2->data;

p2 = p2->prev;

}

}

if (c == 1)

return sum;

}

BIGINT Fibonacci(int n) { //this computes nth Fibonacci number F(n) using the above the add function and returns F(n) in BIGINT type

if (n <= 2 ) {

return bigint("1");

} else {

BIGINT temp = bigint(NULL);

BIGINT f1 = bigint("1");

BIGINT f2 = bigint("1");

int i;

for (i = 3; i <= n; i++) {

temp = f2;

f2 = f1 + f2; //error in this line

f1 = temp;

}

return f2;

}

}

output should be:

1111111111111111111+8888888888888888889=10000000000000000000 Fibonacci(100)=354224848179261915075

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

More Books

Students also viewed these Databases questions