Dorsa R.

asked • 09/04/20

please complete this code :(same variables )

hi this is my code to multiple two large numbers can you please complete it so it divides two numbers too (without changing the variables in the code and please be sure it compile correctly with this variables) :


#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 • 09/05/20

Tutor
4.7 (31)

Math and computer tutor/teacher

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.