Advertisement
FloudMe77

Untitled

Mar 30th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. string n1,n2,n3;
  4. int i,j,l,h,d3,p=0;
  5. int liczba1[1000];
  6. int liczba2[1000];
  7. int liczba3[1000];
  8. int main()
  9. {
  10.     cout << "Podaj pierwsza liczbe: ";
  11.     cin>> n1;
  12.     int d1=n1.length();
  13.     cout<< "Podaj druga liczbe: ";
  14.     cin>> n2;
  15.     int d2=n2.length();
  16.     if(d1>=d2)
  17.     {
  18.       d3=d1-d2;
  19.       for(j=1;j<=d1;j++)
  20.       {
  21.         liczba1[j]=n1[j-1]-48;
  22.       }
  23.       for(i=1;i<=d3;i++)
  24.       {
  25.         liczba2[i]=0;
  26.       }
  27.       for(;i<=d1;i++)
  28.       {
  29.         liczba2[i]=n2[p]-48;
  30.         p+=1;
  31.       }
  32.     }
  33.     else
  34.     {
  35.       d3=d2-d1;
  36.       for(j=1;j<=d2;j++)
  37.       {
  38.         liczba2[j]=n2[j-1]-48;
  39.       }
  40.       for(i=1;i<=d3;i++)
  41.       {
  42.         liczba1[i]=0;
  43.       }
  44.       for(;i<=d1;i++)
  45.       {
  46.         liczba2[i]=n2[p]-48;
  47.         p+=1;
  48.       }
  49.     }
  50.     j-=1;
  51.     h=j;
  52.     for(;j>0;j--)
  53.     {
  54.         liczba3[j]=liczba1[j]+liczba2[j];
  55.         if(liczba3[j]>=10)
  56.         {
  57.             liczba3[j]-=10;
  58.             liczba1[j-1]+=1;
  59.         }
  60.     }
  61.     cout<<"WYNIK TO ";
  62.     if(liczba1[0]!=0)
  63.         cout<<liczba1[0];
  64.     for(int k=1;k<=h;k++)
  65.         cout<<liczba3[k];
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement