发布网友 发布时间:2023-01-08 23:55
共1个回答
热心网友 时间:2023-10-22 17:24
C#程序源码:
static void Main(string[] args)
{
Console.Write("a=");
string a = Console.ReadLine();
Console.Write("b=");
string b = Console.ReadLine();
double x = Convert.ToDouble(a);
double y = Convert.ToDouble(b);
Console.WriteLine("a+b=" + (x + y));
Console.WriteLine("a-b="+ (x-y));
Console.WriteLine("a*b=" + (x * y));
Console.WriteLine("a/b=" + x / y);
Console.ReadKey();
}
程序运行结果:
扩展资料:
C语言实现方法:
#include "pch.h"
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
int num1, num2;
char operate;
scanf("%d %c %d", &num1, &operate, &num2);
switch (operate) {
case '+':
printf("%d", num1 + num2);
break;
case '-':
printf("%d", num1 - num2);
break;
case '*':
printf("%d", num1*num2);
break;
case '/':
printf("%d", num1 / num2);
break;
case '%':
printf("%d", num1%num2);
break;
default:
printf("ERROR");
}
return 0;
}