Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main(){
  5.     char a[10000];
  6.     char b[10000];
  7.     scanf("%s %s", &a, &b);
  8.     char sum[10000];
  9.     int lengthA = 0;
  10.     int lengthB = 0;
  11.  
  12.     int i = 0;
  13.     while(a[i]){
  14.         i++;
  15.     } lengthA = i;
  16.  
  17.     i = 0;
  18.     while(b[i]){
  19.         i++;
  20.     } lengthB = i;
  21.     char temp[10000];
  22.  
  23.     int aplusb;
  24.     int carry = 0;
  25.  
  26.     int max = lengthA;
  27.     int difference = abs(lengthA - lengthB);
  28.     //poravnava
  29.     if(lengthA>lengthB){
  30.         for(i=0; i<lengthA; i++){
  31.             temp[i+difference]=b[i];
  32.         }
  33.         for(i=0; i<=max; i++){
  34.             aplusb = lengthA[max-i]+temp[max-i];
  35.             if(carry == 1) aplusb++;
  36.             if(aplusb>9){
  37.                 carry = 1;
  38.                 aplusb%=10;
  39.             }
  40.             sum[i]=aplusb;
  41.         }
  42.     }
  43.  
  44.     for(i=0; i<=max; i++){
  45.         printf("%c", sum[i]);
  46.     }
  47.  
  48.     /*
  49.     if(lengthB>lengthA){
  50.         max = lengthB;
  51.         for(i=0; i<lengthB; i++){
  52.             temp[i+difference]=a[i];
  53.         }
  54.     }*/
  55.  
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement