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

5) Finally, print the result reversely to get the answer of the expression, 1. A

ID: 3607026 • Letter: 5

Question

5) Finally, print the result reversely to get the answer of the expression, 1. Addition of Two Big Integers As we all have known that integers in C have limited range. But sometimes that limitation just has.ta be conquered. And now we are gepnedo it. Input an integer addition expression (addition between two positive integers), with the number of digits of each integer being at most 1,000. Please note that the result could be 1001 digits. Example Other Requirements eAt least have the following functions defined and called in your code: void reverse(dot, array[], 40JRA) {}, to perform in-place reverse of an integer array 40t, gate 4car c) {), to convert a number character to an integer (e.g. convert '1" to 1) * void addfint, numi], at num2],nt as1) ), to perform digit-by-digit addition of nuni and num2 and store the result into ans. 1211112IE11212212222122122222212221222212121 he answer is Hints 1 Get the input expressio 2) Split your input by into two integer arrays, say n as a string. With every array element holding only 1 digit. Be aware of what you need to do about the conversion from a char to an int. Reverse numi and nun2 so that the two numbers are aligned by lower digits. See below: 3) 123456 654321 381 183 4) Perform digit-by-digit addition by using a loop to iterate through num1 and num2 at the same time, and be cautious when there is a carry. See below 654321 738321 183

Explanation / Answer

There is no data type to do sum of 111111111111111111111111111111111111111111 kind of values so we need to complete this code using strings -

Here is your C code -

#include<stdio.h>
#include<string.h>
int main()
{
int a[255],b[255],sum[255];
int ac=0,bc=0,sc=0;
int r = 0,i;
char num1[255],num2[255],*pa,*pb;
printf("Enter first number : ");
scanf("%s",num1); //taking first number from user in string format
printf(" Enter second number : ");
scanf("%s",num2); //taking second number from user in string format

pa = num1; //pointer to first number
pb = num2; //pointer to second number

//storing first string number in the integer array
while(*pa){ //loop while run untill it get null character
a[ac++] = *pa++ - 48; //48 is ASCII value of character zero
}

//storing first string number in the integer array
while(*pb){
b[bc++] = *pb++ - 48;
}

//additin of two numbers
if(ac<bc){
for(i = ac;i > 0;i--){
sum[sc++]= ((a[i-1] + b[--bc]) + r)%10;
r = ((a[i-1] + b[bc]) + r)/10;
}
while(bc>0){
sum[sc++] = b[--bc] + r;
r = 0;
}
}
else{
for(i = bc;i > 0;i--){
sum[sc++]= ((b[i-1] + a[--ac]) + r)%10;
r = ((b[i-1] + a[ac]) + r)/10;
}
if(ac==0 && r==1)
sum[sc++] = r;
while(ac>0){
sum[sc++] = a[--ac] + r;
r = 0;
}
}
printf("Sum of both number is ");
for(i=sc-1;i>=0;i--)
{
printf("%d",sum[i]);
}
printf(" ");
return 0;
  
}

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