编写一个C#程序,实现从键盘中输入两个数字,屏幕输出这两个数值的和、差、积、商。
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;
}
{
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();
}