Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- string n1,n2,n3;
- int i,j,l,h,d3,p=0;
- int liczba1[1000];
- int liczba2[1000];
- int liczba3[1000];
- int main()
- {
- cout << "Podaj pierwsza liczbe: ";
- cin>> n1;
- int d1=n1.length();
- cout<< "Podaj druga liczbe: ";
- cin>> n2;
- int d2=n2.length();
- if(d1>=d2)
- {
- d3=d1-d2;
- for(j=1;j<=d1;j++)
- {
- liczba1[j]=n1[j-1]-48;
- }
- for(i=1;i<=d3;i++)
- {
- liczba2[i]=0;
- }
- for(;i<=d1;i++)
- {
- liczba2[i]=n2[p]-48;
- p+=1;
- }
- }
- else
- {
- d3=d2-d1;
- for(j=1;j<=d2;j++)
- {
- liczba2[j]=n2[j-1]-48;
- }
- for(i=1;i<=d3;i++)
- {
- liczba1[i]=0;
- }
- for(;i<=d1;i++)
- {
- liczba2[i]=n2[p]-48;
- p+=1;
- }
- }
- j-=1;
- h=j;
- for(;j>0;j--)
- {
- liczba3[j]=liczba1[j]+liczba2[j];
- if(liczba3[j]>=10)
- {
- liczba3[j]-=10;
- liczba1[j-1]+=1;
- }
- }
- cout<<"WYNIK TO ";
- if(liczba1[0]!=0)
- cout<<liczba1[0];
- for(int k=1;k<=h;k++)
- cout<<liczba3[k];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement