Advertisement
anhkiet2507

Bài 3 Tin

Apr 5th, 2019
34,191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. //Bài 3: Nhắc người dùng chọn 1 tùy chọn. Nhắc họ nhập vào 2 số nguyên và in kết quả ứng với tùy chọn đó
  2. #include <iostream>
  3. using namespace std;
  4. int x, y;
  5. void Tong();
  6. void Hieu();
  7.  
  8. int main()
  9. {
  10.     int chon;
  11.     cout << "Lua chon 1 trong 2 tuy chon sau" << endl;
  12.     cout << "1. Tinh tong hai so" << endl;
  13.     cout << "2. Tinh hieu hai so" << endl;
  14.     cout << "Lua chon cua ban: ";
  15.     cin >> chon;
  16.     if (chon = 1) {
  17.         Tong();
  18.     }
  19.     if (chon = 2) {
  20.         Hieu();
  21.     }
  22.     system("pause");
  23.     return 0;
  24. }
  25.  
  26. void Tong()
  27. {
  28.     cout << "Nhap x: ";
  29.     cin >> x;
  30.     cout << "Nhap y: ";
  31.     cin >> y;
  32.     int t;
  33.     t = x + y;
  34.     cout << "Tong cua " << x << " va " << y << " la " << t << endl;
  35. }
  36.  
  37. void Hieu()
  38. {
  39.     cout << "Nhap x: ";
  40.     cin >> x;
  41.     cout << "Nhap y: ";
  42.     cin >> y;
  43.     int h;
  44.     h = x - y;
  45.     cout << "Hieu cua " << x << " va " << y << " la " << h << endl;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement