概述
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
int getOption (void);
void getData (int* num1, int* num2);
float calc (int option, int num1, int num2);
float add (int num1, int num2);
float sub (int num1, int num2);
float mul (int num1, int num2);
float divs (int num1, int num2);
void printData (int nun1, int num2, int option, float result);
int main (void)
{
int option;
int num1;
int num2;
float result;
option = getOption();
getData (&num1, &num2);
result = calc (option, num1, num2);
printData (num1, num2, option, result);
return 0;
}
int getOption (void)
{
int option;
printf("t********************************");
printf("nt* MENU *");
printf("nt* *");
printf("nt* 1. ADD *");
printf("nt* 2. SUBTRACT *");
printf("nt* 3. MULTIPLY *");
printf("nt* 4. DIVIDE *");
printf("nt* *");
printf("nt********************************");
printf("nnPlease type your choice ");
printf("and key return:");
scanf ("%d", &option);
return option;
}
void getData (int* a, int* b)
{
printf("Please enter two integer numbers:");
scanf ("%d %d", a, b);
return;
}
float calc (int option, int num1, int num2)
{
float result;
switch(option)
{
case 1 : result = add (num1, num2);
break;
case 2 : result = sub (num1, num2);
break;
case 3 : result = mul (num1, num2);
break;
case 4 : if (num2 == 0.0)
{
printf("naaError:");
printf("division by zeron");
exit (100);
}
else
result = divs (num1, num2);
break;
default: printf("aOption not availablen");
exit (101);
}
return result;
}
float add (int a, int b)
{
float sum;
sum = a + b;
return sum;
}
float sub (int a, int b)
{
float dif;
dif = a - b;
return dif;
}
float mul (int a, int b)
{
float product;
product = a * b;
return product;
}
float divs (int a, int b)
{
float quotient;
quotient = (float)a / b;
return quotient;
}
void printData (int a, int b, int option, float result)
{
switch(option)
{
case 1 : printf("n%d + %d = %.0fn", a, b, result);
break;
case 2 : printf("n%d - %d = %.0fn", a, b, result);
break;
case 3 : printf("n%d * %d = %.0fn", a, b, result);
break;
case 4 : printf("n%d / %d = %.2fn", a, b, result);
break;
default: printf("naa未知错误!n");
exit (102);
}
return;
}
最后
以上就是坚强鸡为你收集整理的运算加减乘除的c语言程序,求一个计算加减乘除的C语言程序的全部内容,希望文章能够帮你解决运算加减乘除的c语言程序,求一个计算加减乘除的C语言程序所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复