Give two positive integers (may be) of large number, and the sum of two Numbers (the number of two digits - sample)
Input:
Input data have much group, each group of three lines, the first digit, the second the first number 1 behavior, behavior second number 3,
Output:
For each group of input data, output - line,
The Sample Input:
163
The Sample Output:
9
CodePudding user response:
Your topic should be complete, the two Numbers to add the two Numbers should be large, such as the length of 100The original title should also give the range of several? For example, no more than 2000
If that's the case, then you need to define three, slightly more than the maximum length and three string array
Two of them are used to hold data read
The third and used to hold them
The addition and carry yourself to analog to digital, according to the rules of the students learning more than addition, starting from the final alignment carry digital additive and processing
CodePudding user response:
# include & lt; Stdio. H># include & lt; Stdlib. H>
/* run this program using the console pauser or add your own getch, system (" pause ") or the input loop */
# define MAX 2000
Int main (int arg c, char * argv []) {
Char add1/MAX + 2={' 0 '};
Char add2 [MAX + 2)={' 0 '};
Char sum [MAX + 2)={' 0 '};
Printf (" do Input Number 2: \ n ");
The scanf (" % s ", add1 + 1);//keep the first character to 0, for carry behind considering
The scanf (" % s ", add2 + 1);//keep the first character to 0, for carry behind considering
Int len=strlen (add1);//assume that number 2 same length
Int c=0;//the low-order carry
int i=0;
For (I=len - 1; I> 0; I -) {
Int v=add1 - '0' [I] + add2 [I] - '0' + c;
If (v> 10) c=1; The else c=0;
The sum [I]=(10 v %) + '0';
};
If (1==c) {
The sum [0]='1';
Printf (" % s ", sum);
} the else
Printf (" % s ", sum + 1);
return 0;
}
CodePudding user response:
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.htmlI hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html