Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
798 B
3
Indexable
Never
#include <iostream>

int main() {
    int x, y;
    char pt;
    std::cout << "Nhap x: ";
    std::cin >> x;
    
    std::cout << "Nhap y: ";
    std::cin >> y;
    
    std::cout << "Nhap phep tinh: ";
    std::cin >> pt;
    
    switch(pt) {
        case '+':
            printf("%d + %d = %d.\n", x, y, x + y);
            break;
        case '-':
            printf("%d - %d = %d.\n", x, y, x - y);
            break;
        case '*':
            printf("%d * %d = %d.\n", x, y, x * y);
            break;
        case '/': 
            if (y == 0)
                printf("Khong chia duoc\n");
            else
                printf("%d / %d = %d.\n", x, y, x / y);
            break;
        default:
            std::cout << "Nhap sai phep tinh";
            break;
    }
    return 0;
}