发布网友 发布时间:2022-04-24 00:25
共2个回答
热心网友 时间:2023-10-15 10:32
#include<stdio.h>
char *Text[] = {"退出", "两数之和",
"两数之差", "两数乘积",
"两数相乘之商"};
int main(void)
{
double n1, n2, result;
int choice;
printf("请输入两个实数:");
scanf("%lf%lf", &n1, &n2);
while(1)
{
for(int i = 1; i < sizeof(Text)/sizeof(char *); i++)
printf("%d.%s%s\n", i, "输出", Text[i]);
printf("5.%s\n", Text[0]);
printf("请输入你的选择: ");
scanf("%d", &choice);
if(choice == 5)
{
printf("退出关闭程序\n");
return 0;
}
if(choice < 0 || choice > 4)
{
printf("抱歉,查无此选项\n");
continue;
}
switch(choice)
{
case 1:
{
result = n1 + n2;
break;
}
case 2:
{
result = n1 - n2;
break;
}
case 3:
{
result = n1 * n2;
break;
}
case 4:
{
result = n1 / n2;
break;
}
}
printf("%s%s:%.2lf\n", Text[choice], "为", result);
}
return 0;
}
热心网友 时间:2023-10-15 10:33
#include <stdio.h>
#include <stdlib.h>
int main()
{
double a,b;
int c;
while(1)
{
printf("请输入两个实数:");
scanf("%lf%lf",&a,&b);
printf("1.输出两数之和\n");
printf("2.输出两数之差\n");
printf("3.输出两数乘积\n");
printf("4.输出两数相除之商\n");
printf("5.退出\n");
printf("请输入你的选择:");
scanf("%d",&c);
switch(c)
{
case 1:printf("两数之和为 %g\n",a+b);break;
case 2:printf("两数之差为 %g\n",a-b);break;
case 3:printf("两数乘积为 %g\n",a*b);break;
case 4:printf("两数相除之商为 %g\n",a/b);break;
case 5:printf("关闭退出程序\n");exit(0);
default:printf("抱歉,查无此选项\n");break;
}
}
return 0;
}