C语言写个计算器

来源:百度知道 编辑:UC知道 时间:2024/05/15 12:42:52
只要求有加法 和 减法 要求 越简单越好... C 初学者..

#include<stdio.h>
main()
{
int i,j,n;
char m;
scanf("%d",&i);
scanf("%s",&m);
scanf("%d",&j);
switch(m)
{
case '+':n=i+j;break;
case '-':n=i-j;break;
}
printf("%d%s%d=%d",i,m,j,n);
}

#include <stdio.h>
int main()
{
float a = 0;
float b = 0;
int type = 0;

printf("please input two number:");
scanf("%lf%lf",&a,&b);
do
{
printf("1: + \n2: -\n3: exit\n");
printf("please input which operation you want:\n");
scanf("%d",&type);
switch(type)
{
case 1:
printf("the result is :%lf",a+b);
return 0;
case 2:
return 0;
printf("the result is :%lf",a-b);
case 3:
return 0;
default:
printf(&