Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int my_swap(int *a,int *b);
  4. int main(){
  5.  
  6. int x=0,y=0;
  7. int *X=&x,*Y=&y;
  8. cin >> x;
  9. cin >> y;
  10. cout << "Value of x: " << *X << endl;
  11. cout << "Value of y: " << *Y << endl;
  12. cout << *X+*Y << endl;
  13.  
  14. int n=0;
  15. cin >> n;
  16. int a[100];
  17. // int *a = (int*)malloc(sizeof(int)*n);
  18. for(int i = 0; i < n; i++)
  19. {
  20. cin >> a[i];
  21. }
  22. for(int i = n-1;i>=0;i--){
  23. cout << *(a+i) << " ";
  24. }
  25. cout << endl;
  26. cout << "Now without for HEHE:" << endl;
  27. int *b = (a+n);
  28. int *c = a;
  29. while(c!=b){
  30. cout << *c << " ";
  31. c=c+1;
  32. }
  33. cout << endl;
  34. b = (a+n-1);
  35. c = a;
  36. while(b>=c){
  37. cout << *b << " ";
  38. b=b-1;
  39. }
  40. //free(a);
  41. cout << endl;
  42.  
  43. my_swap(&x,&y);
  44. cout << "Value of x: " << *X << endl;
  45. cout << "Value of y: " << *Y << endl;
  46.  
  47. return 0;
  48. }
  49.  
  50. int my_swap(int *a,int *b){
  51. int c = *a;
  52. *a = *b;
  53. *b = c;
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement