fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(void) {
  5. char y[100] = "1032";
  6. char x[100] = "2399";
  7. int carry = 0;
  8.  
  9. char* b = (strlen(x) > strlen(y))? x : y;
  10. char* s = (strlen(x) <= strlen(y))? x : y;
  11.  
  12. for(int i=strlen(s)-1, j=strlen(b)-1; i>=0; --i,--j)
  13. {
  14. b[j] = (b[j]+s[i]+carry-'0');
  15. carry = 0;
  16. if (b[j] > '9')
  17. {
  18. b[j] = (b[j]-'0')%10+'0';
  19. carry = 1;
  20. }
  21. }
  22.  
  23. puts(b);
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0s 2112KB
stdin
asfas
stdout
3431