Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdlib.h>
  3. #include <iostream>
  4. #include <conio.h>
  5. #include <math.h>
  6. using namespace std;
  7.  
  8. int f(int& a, int& b, int x, int y); // по значению
  9.  
  10. int ff(int& a, int& b, int &x, int &y) // со ссылке
  11. {
  12.     if(y == 0)
  13.     {
  14.         return 0;
  15.     }
  16.  
  17.     a = x*y;
  18.     b = x/y;
  19.  
  20.     return 1;
  21. }
  22.  
  23. int f(int& a, int& b, int *x, int *y) // со указателю
  24. {
  25.     if((*y) == 0)
  26.     {
  27.         return 0;
  28.     }
  29.  
  30.     a = (*x)*(*y);
  31.     b = (*x)/(*y);
  32.  
  33.     return 1;
  34. }
  35.  
  36. int main()
  37. {
  38.     setlocale(LC_ALL, "Russian");
  39.  
  40.     int a = 10;
  41.     int b = 5;
  42.  
  43.     cout << "Начальные a = " << a << ", b = " << b << endl;
  44.     cout << "передача x, y по значению - return: " << f(a, b, 21, 7) << endl;
  45.     cout << "a = " << a << endl;
  46.     cout << "b = " << b << endl;
  47.  
  48.     int x = 24;
  49.     int y = 4;
  50.     cout << "передача x, y по ссылке - return: " << ff(a, b, x, y) << endl;
  51.     cout << "a = " << a << endl;
  52.     cout << "b = " << b << endl;
  53.  
  54.     x = 16;
  55.     y = 0;
  56.     cout << "передача x, y по указателю - return: " << f(a, b, &x, &y) << endl;
  57.     cout << "a = " << a << endl;
  58.     cout << "b = " << b << endl;
  59.  
  60.     getch();
  61.  
  62.     return 0;
  63. }
  64.  
  65. int f(int& a, int& b, int x, int y)
  66. {
  67.     if(y == 0)
  68.     {
  69.         return 0;
  70.     }
  71.  
  72.     a = x*y;
  73.     b = x/y;
  74.  
  75.     return 1;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement