-
Notifications
You must be signed in to change notification settings - Fork 0
/
IntegerInquiry.c
53 lines (43 loc) · 934 Bytes
/
IntegerInquiry.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include <string.h>
int main(){
char num[110], sum[110];
int length, i, carry, result, rem, sumlength;
gets(sum);
sumlength = strlen(sum);
while(1){
gets(num);
if(strcmp(num, "0") == 0)
break;
length = strlen(num);
carry = 0;
if(sumlength == length){
for(i=length-1;i>=0;i--){
result = sum[i]-'0' + num[i]-'0' + carry;
rem = result%10;
sum[i] = rem+'0';
carry = result/10;
}
if(carry !=0)
sum[i] = carry+'0';
}else if(sumlength > length){
for(i=1;i<=length;i++){
result = sum[sumlength-i]-'0' + num[length-i]-'0' + carry;
rem = result%10;
sum[sumlength-i] = rem+'0';
carry = result/10;
}
while(carry != 0 && i<=sumlength){
result = sum[sumlength-i]-'0' + carry;
rem = result%10;
sum[sumlength-i] = rem+'0';
carry = result/10;
i++;
}
}else{
}
sumlength = strlen(sum);
}
printf("%s", sum);
return 0;
}