Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1. void plus (char *rez1, char *rez2, char *result, int len, int len1, int len2)
  2. {  
  3.  
  4.     int first  = len1 - 1;
  5.     int second = len2 - 1;
  6.     int res = len - 1;
  7.  
  8.     //  int memoryRes = res;
  9.  
  10.     char memory = '0';
  11.  
  12.     for (; res >-1; first --, second --, res --)
  13.     {
  14.         if (memory == '1')
  15.         {
  16.             /*if    (rez1 [first] == '1' || rez2 [second] == '1')
  17.             {
  18.                 if (rez1 [first] == '1' && rez2 [second] == '1')
  19.                     result [res] = '1';
  20.                
  21.                 else
  22.                     result [res] = '0';
  23.                 memory = '1';
  24.             }
  25.             else
  26.                 result [res] = '1';
  27.                 memory = '0';*/
  28.             if (rez1 [first] == '1' && rez2 [second] == '1')
  29.             {
  30.                 result [res] = '1';
  31.                 //memory = '1';
  32.             }
  33.             if (rez1 [first] == '1' || rez2 [second] != '1')
  34.             {
  35.                 result [res] = '0';
  36.             //  memory = '1';
  37.             }
  38.             if (rez1 [first] != '1' || rez2 [second] == '1')
  39.             {
  40.                 result [res] = '0';
  41.             //  memory = '1';
  42.             }
  43.             if (rez1 [first] == '0' && rez2 [second] == '0')
  44.             {
  45.                 result [res] = '1';
  46.                 memory = '0';
  47.             }
  48.  
  49.            
  50.         }
  51.         else
  52.         {
  53.             if (rez1 [first] == '1' && rez2 [second] == '1')
  54.             {
  55.                 result [res] = '0';
  56.                 memory = '1';
  57.             }
  58.             if (rez1 [first] == '1' || rez2 [second] != '1')
  59.             {
  60.                 result [res] = '1';
  61.             //  memory = '0';
  62.             }
  63.             if (rez1 [first] != '1' || rez2 [second] == '1')
  64.             {
  65.                 result [res] = '1';
  66.             //  memory = '0';
  67.             }
  68.             if (rez1 [first] == '0' && rez2 [second] == '0')
  69.             {
  70.                 result [res] = '0';
  71.             //  memory = '0';
  72.             }
  73.  
  74.  
  75.  
  76.             /*if   (rez1 [first] == '1' || rez2 [second] == '1')
  77.             {
  78.                 if (rez1 [first] == '1' && rez2 [second] == '1')                 
  79.                     result [res] = '0';        
  80.                 memory = '1';
  81.                 else    result [res] = '1';
  82.                
  83.             }
  84.             else result [res] = '0';*/
  85.         }
  86.  
  87.     }
  88.     if (result [0] != '0' && result [0] != '1') { result [0] = '0'; }
  89.  
  90.     /* int k;
  91.  
  92.     for (k = 0; result [k] == '0' || result [k] == '1'; k++);
  93.  
  94.     result [k] = '\0';*/
  95.  
  96. for (int i = len-1; i > -1; i--)
  97.     {          
  98.         cout << result[i];
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement