Constraints
Time Limit: 1 secs, Memory Limit: 8 MB
Description
Input A and B, output A+B
Input
Input two values, A and B.(0<=A,B<10^100)
Output
Output the result of A+B.
Sample Input
1234567890123456789
987654321
Sample Output
1234567891111111110
- #include<stdio.h>
- #include<string.h>
- void init(int*arr,int*len){
- int i;
- char st[101];
- scanf("%s", st);
- *len = strlen(st);
- for(i =0; i <*len; i++)
- arr[i]= st[*len -1- i]-'0';
- }
- int main(){
- int a[100], b[100], c[101], m, n, i, j, k, tmp;
- init(a,&n);
- init(b,&m);
- k = m > n ? m : n;
- for(i =0; i <= k; i++) c[i]=0;
- for(i = n; i < k; i++) a[i]=0;
- for(i = m; i < k; i++) b[i]=0;
- for(i =0; i < k; i++){
- tmp = a[i]+ b[i]+ c[i];
- c[i]= tmp %10;
- c[i+1]= tmp /10;
- }
- if(c[k]>0) k++;
- for(i = k; i >0; i--) printf("%d", c[i -1]);
- puts("");
- return0;
- }