Boolean flag = true; while (flag) { char a ; float number1,number2,result = 0; printf("a表示加法\n"); printf("b表示减法\n"); printf("a表示乘法\n"); printf("d表示除法\n"); printf("q表示退出\n"); printf("请输入您的选择:"); scanf("%c",&a); switch (a) { case ‘a‘: printf("请输入第一个数:\n"); scanf("%f",&number1); printf("请输入第二个数:\n"); scanf("%f",&number2); result = number1 + number2; printf("%.1f + %.1f = %.1f\n",number1,number2,result); break; case ‘b‘: printf("请输入第一个数:\n"); scanf("%f",&number1); printf("请输入第二个数:\n"); scanf("%f",&number2); result = number1 - number2; printf("%.1f - %.1f = %.1f\n",number1,number2,result); break; case ‘c‘: printf("请输入第一个数:\n"); scanf("%f",&number1); printf("请输入第二个数:\n"); scanf("%f",&number2); result = number1 * number2; printf("%.1f + %.1f = %.1f\n",number1,number2,result); break; case ‘d‘: printf("请输入第一个数:\n"); scanf("%f",&number1); printf("请输入第二个数:\n"); scanf("%f",&number2); result = number1 / number2; printf("%.1f + %.1f = %.1f\n",number1,number2,result); break; case ‘q‘: flag = false; printf("已经退出了"); break; default: break; }
时间: 2024-12-09 10:56:34