Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A simple calculator made in c language #33

Open
Akhil-kotipali opened this issue Jun 27, 2024 · 1 comment
Open

A simple calculator made in c language #33

Akhil-kotipali opened this issue Jun 27, 2024 · 1 comment

Comments

@Akhil-kotipali
Copy link

No description provided.

@Halsjsko
Copy link

Halsjsko commented Nov 9, 2024

#include <stdio.h>
#include <stdlib.h>

int main() {
double num1, num2;
char op;

printf("输入第一个数字:");
scanf("%lf", &num1);

printf("输入运算符 (+、-、*、/): ");
scanf(" %c", &op);

printf("输入第二个数字:");
scanf("%lf", &num2);

switch (op) {
    case '+':
        printf("%.2lf + %.2lf = %.2lf\n", num1, num2, num1 + num2);
        break;
    case '-':
        printf("%.2lf - %.2lf = %.2lf\n", num1, num2, num1 - num2);
        break;
    case '*':
        printf("%.2lf * %.2lf = %.2lf\n", num1, num2, num1 * num2);
        break;
    case '/':
        if (num2!= 0) {
            printf("%.2lf / %.2lf = %.2lf\n", num1, num2, num1 / num2);
        } else {
            printf("除数不能为零!\n");
        }
        break;
    default:
        printf("无效的运算符!\n");
}

return 0;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants