用C语言设计一个简单的计算器

来源:百度知道 编辑:UC知道 时间:2024/04/30 22:17:26
用C语言设计一个简单的计算器,要求能够对输入的数
1.进行+,-,*,/,运算;
2.可以带括号;
3.不限定运算式的输入长度.
4.要支持简单的括号运算
5.刚学c语言不久,不要编的太难

#include<stdio.h>
void add(int a,int b,int c)
{
c=a+b;
printf("%d\t",c);
printf("\n");
}
void minus(int a,int b,int c)
{
c=a-b;
printf("%d\t",c);
printf("\n");
}
void multiplication(int a,int b,int c)
{
c=a*b;
printf("%d\t",c);
printf("\n");
}
void div(int a,int b,int c)
{
(float)c=(float)a/(float)b;
printf("%f\t",c);
printf("\n");
}
main()
{
int a,b,c;
char p;
puts("input A:\n");
scanf("%d",&a);
puts("input B:\n");
scanf("%d",&b);
puts("input operation:\n");
getchar();
p=getchar();
if(p=='+') add(a,b,c);else
if(p=='-') minus(a,b,c);else
if(p=='*