求C语言大神,期末考试唯一的一道题,希望能认真对待,测试完没问题马上采纳!谢谢!
展开全部
这种题,就是练练打字而已。那就练练吧——
//#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;
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#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;
}
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;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询