Dorsa R.

asked • 08/30/20

please complete this code :

hi this is my code to multiple two large numbers can you please complete it so it divides two numbers too (without changing the names) :


#include <stdio.h>

#include <stdlib.h>

#include <string.h>



int main()

{

int a[200],b[200];

int answer[200]={0};

int i,j,tmp;

char s[100],d[100];

puts("please enter 2 numbers :");

scanf(" %s",s);

scanf(" %s",d);

int l1 = strlen(s);

int l2 = strlen(d);

for(i = l1-1,j=0;i>=0;i--,j++)

{

a[j] = s[i]-'0';

}

for(i = l2-1,j=0;i>=0;i--,j++)

{

b[j] = d[i]-'0';

}

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

{

for(j = 0;j < l1;j++)

{

answer[i+j] += b[i]*a[j];

}

}

for(i = 0;i < l1+l2;i++)

{

tmp = answer[i]/10;

answer[i] = answer[i]%10;

answer[i+1] = answer[i+1] + tmp;

}

for(i = l1+l2; i>= 0;i--)

{

if(answer[i] > 0)

break;

}

printf("result : ");

for( ;i >= 0;i--)

{

printf("%d",answer[i]);

}

return 0;

}

1 Expert Answer

By:

Patrick B. answered • 08/30/20

Tutor
4.7 (31)

Math and computer tutor/teacher

Dorsa R.

thanks for answering but i get this error : 1.(it is undeclared ) quotient=1; 2.(as you know we have strings here so they are "char" but others are "int" so i get this error for while loop :invalid operands to binary have int and char ) while ( (partial_product = quotient * divisor) < dividend) { quotient ++; } 3.(remainder is undeclared too ) remainder = dividend - partial_product;
Report

08/31/20

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.