#include<stdio.h>
int main()
{
//加减乘除函数的声明
int addition(int x,int y);
int subtraction(int x,int y);
int multiplication(int x,int y);
float division(int x,int y);
//定义两个数,和一个字符
char character;
int a,b;
//输入两个数,和一个字符
printf("请输入需要加减乘除的两个整数,请用逗号隔开:\n");
scanf("%d,%d",&a,&b);
printf("请输入需要做的那种运算,A/a代表加法,B/b代表减法,C/c代表乘法,D/d代表除法:\n");
scanf("%c",&character);
//调用函数完成对两个数的加减乘除
switch(character)
{
case 'a':
case 'A': printf("%d",addition(a,b));break;
case 'b':
case 'B': printf("%d",subtraction(a,b));break;
case 'c':
case 'C': printf("%d",multiplication(a,b));break;
case 'd':
case 'D': printf("%f",division(a,b));break;
default :putchar('\a');
}
return 0;
}
//加减乘除函数的实现
int addition(int x,int y)
{
return x+y;
}
int subtraction(int x,int y)
{
return x-y;
}
int multiplication(int x,int y)
{
return x*y;
}
float division(int x,int y)
{
return (float)x/y;
} |
|