Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include<iostream>
  2. #include<iomanip>
  3. using namespace std;
  4.  
  5.  
  6. void swap(int* a, int* b)
  7. {
  8. int buf = *a;
  9. *a = *b;
  10. *b = buf;
  11. }
  12.  
  13. void swap(int& a, int& b)
  14. {
  15. int buf = a;
  16. a = b;
  17. b = buf;
  18. }
  19. void swap2(int a, int b)
  20. {
  21. int buf = a;
  22. a = b;
  23. b = buf;
  24. }
  25.  
  26.  
  27. int sum(int* a,int b)
  28. {
  29. return *a + b;
  30. }
  31. int dif(int& a,int* b)
  32. {
  33. return a - *b;
  34. }
  35. void mult(int* a,int& b,int& res)
  36. {
  37. res = *a * b;
  38. }
  39. void div(int& a,int* b,double& res)
  40. {
  41. res = (double)a / *b;
  42. }
  43.  
  44.  
  45.  
  46. int main()
  47. {
  48. /*int g = 233;
  49. int* p = &g;
  50. cout << g << endl;
  51. cout << &g << endl;
  52. cout << *p << endl;
  53.  
  54. int h = 12;
  55. int& r = h;
  56. r += 5;
  57. cout << h << endl;
  58. */
  59.  
  60.  
  61.  
  62. int a = 0,
  63. b = 0,
  64. c = 0,
  65. res = 0;
  66. /*cin >> a >> b;
  67. swap2(a, b);
  68. cout << a << " " << b << endl;
  69. swap(&a,&b);
  70. cout << a << " " << b << endl;
  71. swap(a,b);
  72. cout << a << " " << b << endl;*/
  73. double resDiv = 0;
  74. cout << "Enter first number: ";
  75. cin >> a;
  76. cout << "Enter second number: ";
  77. cin >> b;
  78. cout <<a<<" + "<<b<<" = "<< sum(&a,b)<<endl;
  79. cout <<a<<" - "<<b<<" = "<< dif(a,&b)<<endl;
  80. mult(&a,b,res);
  81. cout <<a<<" * "<<b<<" = "<<res<<endl;
  82. div(a,&b,resDiv);
  83. cout <<a<<" / "<<b<<" = "<<setprecision(2)<<resDiv<<endl;
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement