求C语言大神,期末考试唯一的一道题,希望能认真对待,测试完没问题马上采纳!谢谢!

 我来答
White_MouseYBZ
2015-06-19 · TA获得超过4万个赞
知道大有可为答主
回答量:2.1万
采纳率:82%
帮助的人:6687万
展开全部

这种题,就是练练打字而已。那就练练吧——

//#include "stdafx.h"//vc++6.0加上这一行.
#include "stdio.h"
int main(void){
    double a,b;
    int n;
    printf("|-----------------------------------------------|\n");
    printf("|                    calculator                 |\n");
    printf("|-----------------------------------------------|\n");
    printf("|                     1---add                   |\n");
    printf("|                     2---sub                   |\n");
    printf("|                     3---mul                   |\n");
    printf("|                     4---div                   |\n");
    printf("|                     0---quit                  |\n");
    printf("|-----------------------------------------------|\n");
    while(1){
        printf("Please choice(0-4):");
        if(scanf("%d",&n),n==1){
            printf("Please the first data:");
            scanf("%lf",&a);
            printf("Please the second data:");
            scanf("%lf",&b);
            printf("Result of calculator:\n%f + %f = %f\n",a,b,a+b);
        }
        else if(n==2){
            printf("Please the first data:");
            scanf("%lf",&a);
            printf("Please the second data:");
            scanf("%lf",&b);
            printf("Result of calculator:\n%f - %f = %f\n",a,b,a-b);
        }
        else if(n==3){
            printf("Please the first data:");
            scanf("%lf",&a);
            printf("Please the second data:");
            scanf("%lf",&b);
            printf("Result of calculator:\n%f x %f = %f\n",a,b,a*b);
        }
        else if(n==4){
            printf("Please the first data:");
            scanf("%lf",&a);
            while(1){
                printf("Please the second data:");
                if(scanf("%lf",&b),b) break;
                printf("Error,divisor cannot be 0,redo:");
            }
            printf("Result of calculator:\n%f ÷ %f = %f\n",a,b,a/b);
        }
        else if(n==0) break;
        printf("Continue(y/n)?\n");
        getchar();
        if((getchar()|0x20)=='n') break;
    }
    return 0;
}
匿名用户
2015-06-19
展开全部
#include <stdio.h>
#include <math.h>

void main()
{
int id;
double a, b, c;
char d;
printf("                |---------------------------------------------|\n");
printf("                |               calculator                    |\n");
printf("                |---------------------------------------------|\n");
printf("                |                1---add                      |\n");
printf("                |                2---sub                      |\n");
printf("                |                3---mul                      |\n");
printf("                |                4---div                      |\n");
printf("                |                0---quit                     |\n");
printf("                |---------------------------------------------|\n");
while (1)
{
printf("                   please choice<0-4>:");
scanf("%d", &id);
if (id == 0)
printf("quit\n");
else
{
printf("                   please the first data:");
scanf("%lf", &a);
printf("                   please the second data:");
scanf("%lf", &b);
printf("                   result of calulator:\n");
if (id == 4 && fabs(b) < 1e-6)
printf("                   the second data is error(=0)\n");
else
{
if (id == 1) c = a + b;
else if (id == 2) c = a - b;
else if (id == 3) c = a * b;
else if (id == 4) c = a / b;
printf("                   %lf - %lf = %lf\n", a, b, c);
}
}
printf("                   continue (y/n)? ");
fflush(stdin);
scanf("%c", &d);
fflush(stdin);
if (d == 'n') break;
}
}
更多追问追答
追问

大神 这是什么情况?
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
安然不安然书生
2015-06-19 · TA获得超过749个赞
知道小有建树答主
回答量:909
采纳率:50%
帮助的人:371万
展开全部
#include <stdio.h>
int main()
{
int choice = 0;
int firstNum;
int secondNum;
printf("[1] Add\n");
printf("[2] Subtract\n");
printf("[3] Multiply\n");
printf("[4] Divide\n");
printf("Enter your choice : ");
scanf("%d", &choice);
printf("first num: ");
scanf("%d", &firstNum);
printf("Second num: ");
scanf("%d", &secondNum);
switch(choice)
{
case 1: // Add
printf("%d + %d = %d\n",firstNum,secondNum, firstNum + secondNum);
break;
case 2:// Subtract
printf("%d - %d = %d\n",firstNum,secondNum, firstNum - secondNum); // Subtract
break;
case 3:
printf("%d - %d = %d\n",firstNum,secondNum, firstNum * secondNum);// Multiply
break;
case 4:
printf("%d - %d = %d\n",firstNum,secondNum, firstNum / secondNum); // Divide
break;
default:
printf("Enter Wrong!\n");
}
return 0;
}
追问

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式