#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
double Add(double x, double y);
double Sub(double x, double y);
double Mul(double x, double y);
double Div(double x, double y);
double (*function[4])(double, double) = {Add, Sub, Mul, Div};
int main()
{
double x = 0, y = 0, a, b, c;
int choose = 0;
int Ary_10;
char Ary_2[20], Ary_8[20], Ary_16[20];
while(1)
{
system("cls");
printf ("┏--------------------------------------------- ┓\n");
printf ("┇请选择你要计算的方法: ┇\n");
printf ("┣--------------------------------------------- ┫\n");
printf ("┇ 1、加法 5、进制转换 ┇\n");
printf ("┇ 2、减法 6、求一元二次方程 ┇\n");
printf ("┇ 3、乘法 ┇\n");
printf ("┇ 4、除法 0、退出 ┇\n");
printf ("┗--------------------------------------------- ┛\n");
printf ("Please write down the number:");
scanf ("%d", &choose);
switch(choose)
{
case 0:
exit(0);
break;
case 1:
printf("\n请输入两个运算符(x + y):");
scanf("%lf + %lf", &x, &y);
printf("\n结果为:%6.2f\n", function[0](x, y));
system("pause");
break;
case 2:
printf("\n请输入两个运算符(x - y):");
scanf("%lf - %lf", &x, &y);
printf("\n结果为:%6.2f\n", function[1](x, y));
system("pause");
break;
case 3:
printf("\n请输入两个运算符(x * y):");
scanf("%lf * %lf", &x, &y);
printf("\n结果为:%6.2f\n", function[2](x, y));
system("pause");
break;
case 4:
printf("\n请输入两个运算符(x / y):");
scanf("%lf / %lf", &x, &y);
printf("\n结果为:%6.2f\n", function[3](x, y));
system("pause");
break;
case 5:
printf("\n请输入要转换的数:");
scanf("%d", &Ary_10);
itoa (Ary_10, Ary_2 , 2);
itoa (Ary_10, Ary_8 , 8);
itoa (Ary_10, Ary_16 , 16);
printf("\n二进制: %s\n", &Ary_2);
printf("\n八进制: %s\n", &Ary_8);
printf("\n十六进制: %s\n", &Ary_16);
system("pause");
break;
case 6:
printf("请输入一元一次方程的a b c三个数:");
scanf("%lf %lf %lf", &a, &b, &c);
printf("a:%lf b:%lf c:%lf\n", a, b, c);
double Rad = b*b - 4*a*c;
printf("Rad %lf\n", Rad);
if (Rad > 0)
{
double x1 = (-b + sqrt(Rad)) / (2*a);
double x2 = (-b - sqrt(Rad)) / (2*a);
printf("有两个解 x1 = %lf, x2 = %lf\n", x1, x2);
}
else if (Rad == 0)
{
double x1 = -b / (2*a);
printf("只有一个解 x1 = %lf\n", x1);
}
else
{
printf("无解\n");
}
system("pause");
break;
default :
printf(" 请输入正确的数字。\n");
system("pause");
break;
}
}
}
double Add(double x, double y)
{
return x + y;
}
double Sub(double x, double y)
{
return x - y;
}
double Mul(double x, double y)
{
return x * y;
}
double Div(double x, double y)
{
return x / y;
}
|