Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ~~~
- SWITCH POINTERS
- #include<iostream>
- using namespace std;
- int pointersswitch(int **p,int **q)
- {swap(*p,*q);
- return 0;}
- int *a=new int;
- int *b=new int;
- int main()
- {cout<<a<<endl<<b;
- cout<<endl;
- pointersswitch(&a,&b);
- cout<<a<<endl<<b;}
- ~~~
- SWITCH DATA
- #include<iostream>
- using namespace std;
- int v[3]={73,21,53};
- int l[3]={16,35,27};
- int *p; int *q;
- int swapdata(int *p,int *q)
- {swap(*p,*q);
- return 0;}
- int main()
- {
- for(int h=0;h<=2;h++)
- {p=v+h;q=l+h;swapdata(p,q);}
- for(int i=0;i<=2;i++) cout<<v[i]<<" ";cout<<endl;
- for(int j=0;j<=2;j++) cout<<l[j]<<" ";}
- ~~~
- SWITCH DATA 2
- #include<iostream>
- using namespace std;
- int v[3]={7,21,13}; int n1=2, n2=3;
- int l[4]={29,46,19,51};
- int *p; int *q;
- int swapdata(int **p,int **q)
- {swap(*p,*q);
- return 0;}
- int main()
- {p=v; q=l;
- swapdata(&p,&q);
- for(int i=0;i<=n1;i++)
- cout<<*(q+i)<<" ";
- cout<<endl;
- for(int i=0;i<=n2;i++)
- cout<<*(p+i)<<" ";}
- ~~~
- ADUNARE
- #include<iostream>
- using namespace std;
- int v[3]={7,21,13}; int n1=2, n2=3;
- int l[4]={29,46,19,51};
- int *p; int *q;
- int swapdata(int **p,int **q)
- {swap(*p,*q);
- return 0;}
- int main()
- {p=v; q=l;
- swapdata(&p,&q);
- for(int i=0;i<=n1;i++)
- cout<<*(q+i)<<" ";
- cout<<endl;
- for(int i=0;i<=n2;i++)
- cout<<*(p+i)<<" ";}
- ~~~
- ADUNARE VECTOR
- #include<iostream>
- #include<cmath>
- using namespace std;
- int a=7,b=39,p[100],q[100],v[100];
- int adunare(int a, int b)
- {int i=0,j=0,h=0,k,m=0;
- while(a>0)
- {p[i]=a%10;
- i++;
- a=a/10;}
- for(int y=0;y<i;y++) cout<<p[i]<<" ";cout<<endl;
- while(b>0)
- {q[j]=b%10;
- j++;
- b=b/10;}
- for(int y=0;y<j;y++) cout<<q[i]<<" ";cout<<endl;
- if(j>i)
- for(h=0;h<j-i;h++)
- {p[h+1]=p[h];
- p[h]=0;}
- if(i>j)
- for(h=0;h<i-j;h++)
- {q[h+1]=q[h];
- q[h]=0;}
- for(k=max(i,j);k>0;k--)
- {v[k]=p[k]+q[k];
- if(m==1) { v[k]++;m=0;}
- if(p[k]+q[k]>0)
- m=1;}
- for(int x=0;x<max(i,j);x++)
- cout<<v[x];
- return 0;}
- int main()
- {
- int i=0,j=0,h=0,k,m=0;
- while(a>0)
- {p[i]=a%10;
- i++;
- a=a/10;}
- for(int y=0;y<i;y++) cout<<p[i]<<" ";cout<<endl;
- while(b>0)
- {q[j]=b%10;
- j++;
- b=b/10;}
- for(int y=0;y<j;y++) cout<<q[i]<<" ";cout<<endl;
- if(j>i)
- for(h=0;h<j-i;h++)
- {p[h+1]=p[h];
- p[h]=0;}
- if(i>j)
- for(h=0;h<i-j;h++)
- {q[h+1]=q[h];
- q[h]=0;}
- for(k=max(i,j);k>0;k--)
- {v[k]=p[k]+q[k];
- if(m==1) { v[k]++;m=0;}
- if(p[k]+q[k]>0)
- m=1;}
- for(int x=0;x<max(i,j);x++)
- cout<<v[x];
- }
- ~~~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement