一个关于计算器编写的问题
问题如下:1.统计的运算里没法按照程序的设计终止。
2.while里面的scanf会被跳过奇数次次
3.排列组合无法运算
代码如下:
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
void main()
{
void la(),start(),help(),order(),work(),welcome(),end(),endd();
char a,start_0,order_,order_0,choose_001,qwer;
signed long double x,y,z;
long int n,poi;
la();
start();
la();
welcome();
printf("\n\t\t按照提示,选择要使用的界面");
while(1)
{
printf("\n\t\t输入指令:");
printf("\n\t\t\"h\"-->查看帮助\n");
printf("\n\t\t\"o\"-->查看指令\n");
printf("\n\t\t\"w\"-->进行运算\n\n输入选择的指令: ");
scanf("%c",&start_0);
switch(start_0)
{
case 'h':help();system("pause");break;
case 'o':order();system("pause");break;
case 'w':system("pause");break;
case '\n':
default :printf("\n\n\t\t输入有误,请重新输入");system("pause");break;
}
if(start_0=='w')break;
}
la();
while(1)
{
printf("")
printf("\n\t\t请选择运算模式:\n\n\torder:");
scanf("%c",&order_);
switch(order_)
{
case'a':
{
la();
printf("\n\t\t***开始加法运算***\n");
system("pause");
printf("\n\t加数1: a=");
scanf("%lf",&x);
printf("\n\t加数2: b=");
scanf("%lf",&y);
printf("\n\t和=%lf",x+y);
end();
}break;
case'b':
{
la();
printf("\n\t\t***开始减法运算***\n\n");
system("pause");
printf("\t被减数: a=");
scanf("%lf",&x);
printf("\n\t减数: b=");
scanf("%lf",&y);
z=x+y;
printf("\n\t差=%lf",z);
end();
}break;
case'c':
{
la();
printf("\n\t\t***开始乘法运算***\n\n");
system("pause");
printf("乘数: a=");
scanf("%lf",&x);
printf("乘数: b=");
scanf("%lf",&y);
z=x*y;
printf("积=%lf",z);
end();
}break;
case'd':
{
la();
printf("\n\t\t***开始除法运算***\n\n");
system("pause");
printf("被除数: a=");
scanf("%lf",&x);
printf("除数: b=");
scanf("%lf",&y);
z=x/y;
printf("商=%lf",z);
end();
}break;
case'e':
{
la();
printf("\n\t\t***开始阶乘运算***\n\n");
system("pause");
int z=1;
int i;
printf("\t\t输入一个数,得到阶乘结果\n");
printf("\t\tn=");
scanf("%ld",&n);
for(i=1;i<=n;i++)
z=z*i;
printf("\t\tn!=%ld",z);
end();
}break;
case'f':
{
la();
printf("\n\t\t***开始绝对值运算(此运算比较没用...)***\n\n");
system("pause");
printf("\t\t输入数: x=");
scanf("%lf",&x);
printf("\n\t\t|x|=%d",fabs(x));
end();
}break;
case'g':
{
la();
printf("\n\t\t***开始统计运算***\n\n");
system("pause");
long double *p;
long double a[1000];
long double s=0;
int t=0,m;
p=&a[0];
char choose_1;
while(1)
{
printf("\n\t请输入统计的值,若想结束,则输入 \"5724\"");
++t;
m=t;
printf("\n\tx%d=",t);
scanf("%lf",p+t);
if(*(p+t)==5724)
break;
}
printf("请选择进行的运算:");
printf("a.求和\nb.求平均值\nc.求标准差");
char abc;
scanf("%c",&abc);
while(1)
{
switch(abc)
{
case'a':
{
long double s=0;
printf("\n\n\t\t和=");
for(t=0;t<m;t++)
s=s+*(p+t);
printf("%lf",s);
break;
}
case'b':
{
printf("\n\n\t\t平均值=");
for(t=0;t<m;t++)
s=s+*(p+t);
printf("%lf",s/m);
break;
}
case'c':
{
long double std=0;
printf("\n\n\t\t方差=");
for(t=0;t<m;t++)
s=s+*(p+t);
for(t=0;t<m;t++)
std=std+(*(p+t)-s/m)*(*(p+t)-s/m);
printf("%lf",std/m);
break;
}
case'd':
{
long double std=0;
printf("\n\n\t\t标准差=");
for(t=0;t<m;t++)
s=s+*(p+t);
for(t=0;t<m;t++)
std=std+(*(p+t)-s/m)*(*(p+t)-s/m);
printf("%lf",sqrt(std/m));
break;
}
}
printf("\n\n\t\t1.返回运算模式选择界面\n\n\t\t2.继续此数据的运算");
if(getchar()=='1')
break;
}
break;
}
case'h':
{
printf("\n\t\t开始幂运算\n\n");
printf("\n底数=");
scanf("%lf",&x);
printf("指数=");
scanf("%lf",&y);
printf("\n结果=%lf",pow(x,y));
break;
}
case'i':
{
printf("\n\t***开始一元二次方程运算***\n\n");
long double a,b,c,disc,x1,x2,realpart,imagpart;
printf("\t按 ax^2+bx+c=0 的格式输入a,b,c");
printf("\na=");
scanf("%lf",&a);
printf("b=");
scanf("%lf",&b);
printf("c=");
scanf("%lf",&c);
printf("此方程");
if(fabs(a)<=1e-6)
{
if(fabs(b)<=1e-6)
printf("非一元二次方程且无解");
else
printf("为一元一次方程\nx1=%lf",-c/b);
}
else
{
disc=b*b-4*a*c;
if(fabs(disc)<=1e-6)
printf("有两个相等的实数解:%18.7f\n",-b/(2*a));
else
if(disc>1e-6)
{
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
printf("有两个不相同的实数解:\nx1=%18.7f",x1);
printf("\nx2=%18.7f",x2);
}
else
{
realpart=-b/(2*a);
imagpart=sqrt(-disc)/(2*a);
printf("有复数解:\n");
printf("\t%18.7f+%18.7fi\n",realpart,imagpart);
printf("\t%18.7f-%18.7fi\n",realpart,imagpart);
}
}
break;
}
case'j':
{
printf("\n\t***开始开方运算***\n");
while(1)
{
printf("\n底数=");
scanf("%lf",&x);
if(x<0)
printf("输入数值有误,重新输入\n");
else
break;
}
printf("\n结果=%lf",sqrt(x));
end();
}break;
case'k':
{
printf("\n\t***开始三角函数运算***");
char choose_2,angle;
while(1)
{
printf("输入弧度值:");
scanf("%lf",&x);
printf("选择三角函数名:\na.sin\nb.cos\nc.tan");
scanf("%c",&angle);
switch(angle)
{
case'a':printf("\nsin %c =%18.7f",angle,sin(x));break;
case'b':printf("\ncos %c =%18.7f",angle,cos(x));break;
case'c':printf("\ntan %c =%18.7f",angle,tan(x));break;
}
printf("返回选择运算模式界面?");
printf("\n\n是为(Y),否为(N)\n\n");
scanf("%c",&choose_2);
if(choose_2=='Y')
break;
}
break;
}
case'l':
{
printf("\n\t***开始反三角函数运算***");
char choose_3,aangle;
while(1)
{
while(1)
{
printf("输入实数(-1~1):\nx=");
scanf("%lf",&x);
if((x>=1)||(x<=-1))
printf("输入有误,重新输入");
else
break;
}
printf("选择函数名");
printf("\na.arcsin\nb.arccos\nc.arctan\n\n");
scanf("%c",aangle);
switch(aangle)
{
case'a':printf("\narcsin %c =%lf",aangle,asin(x));break;
case'b':printf("\narccos %c =%lf",aangle,acos(x));break;
case'c':printf("\narctan %c =%lf",aangle,atan(x));break;
}
printf("返回选择运算模式界面?");
printf("\n\n是为(Y),否为(N)\n\n");
scanf("%c",&choose_3);
if(choose_3=='Y')
break;
}
break;
}
case'm':
{
printf("\n***进入自然对数运算***");
while(1)
{
printf("\n底数=");
scanf("%lf",&x);
if(x<0)
printf("输入数值有误,重新输入\n");
else
break;
}
printf("\nIn %lf =%lf",x,log(x));
break;
}
case'n':
{
la();
printf("\n\n\t***开始排列组合运算***");
int m,n,n_1=1,m_1=1,m_2=1,ac;
printf("\n\n\t\t输入上标:");
scanf("%d",&m);
printf("\n\t\t输入下标:");
scanf("%d",&n);
printf("\n\t选择运算:\n\n\t1.排列\n\n\t2.组合\n");
scanf("%d",&ac);
if(ac==1)
{
int i,n_1=1,m_1;
for(i=0;i<=n;i++)
n_1=n_1*i;
for(i=0;i<=n-m;i++)
m_1=m_1*i;
printf("\n\n\t\t结果:\n\n\t%d",(n_1/m_1));
}
else
{
int i;
for(i=0;i<=n;i++)
n_1=n_1*i;
for(i=0;i<=n-m;i++)
m_1=m_1*i;
for(i=0;i<=m;i++)
m_2=m_2*i;
printf("\n\n\t\t结果:\n\n\t%d",(n_1/(m_1*m_2)));
}
}break;
case'z':
{
endd();
goto loop_1;
}
}
system("pause");
}
loop_1:;
}
void la()
{
int i;
printf("\12");
for(i=0;i<=7;i++)
printf("L\\ /");
printf("L");
printf("\n");
for(i=0;i<=7;i++)
printf(" \\ / ");
printf("\n");
for(i=0;i<=7;i++)
printf(" KB ");
printf("\n");
for(i=0;i<=7;i++)
printf(" / \\ ");
printf("\n");
for(i=0;i<=7;i++)
printf("A/ \\");
printf("A");
printf("\n");
}
void start()
{
printf("000000000000000000000000000000000000000000000000 000000000 000000000000000\n");
printf("0000000000000000000000 00000000000000000000 00000000 0000000000000000\n");
printf("00000 00000000000000 0000000000000000000 0000 0000000000000\n");
printf("000000 0000000000000 00000000000000000 0 00000 0 0000000000000000\n");
printf("0000000 00000 000000000000000000000000000000000000000000\n");
printf("0000000000000000000000 0000000000000000000000 000000000000000000\n");
printf("00 0000000000 00000000000000000000 00000000 0000000000000000\n");
printf("000000000 0000000000 00000000000000000000 0000000000000000\n");
printf("000000000 0000000000 00000000000000000000 00000000 0000000000000000\n");
printf("000000000 0000000000 00000000000000000000 0000000000000000\n");
printf("00000000 00000000000 00000000000000000000 00000000 0000000000000000\n");
printf("00000000 000 00000 0000000000000000000000 000000000000000000\n");
printf("00000000 0 0000000 00000000000000000000000000000000000000000000000000\n");
printf("00000000 000000000 0000000000000000000000 00000 000000000000000000\n");
printf("0000000 0000000000 000000000000000 0000000000\n");
printf("0000000 000000000000 000000000000000000000 00000 000000000000000000\n");
printf("0000000 0000000000000 00000000000000000000 000000 000000000000000000\n");
printf("00000000000000000000000 0000000000000000000 00000000 000000000000000000\n");
printf("0000000000000000000000000000000000000000000 0000000000 000000000000000000\n");
printf("\n");
system("pause");
}
void help()
{
printf("\n\n\t\t\t **************");
printf("\n\t\t\t****帮助界面****");
printf("\n\t\t\t **************");
printf("\n\n\t选择指令时,输入中文前的符号即可完成指令的选择\n\n");
printf("按下任意键以返回选择界面\n\n");
}
void order()
{
char a;
la();
printf("\n\ta.加法运算\t");
printf("\tb.减法运算\n");
printf("\n\tc.乘法运算\t");
printf("\td.除法运算\n");
printf("\n\te.阶乘运算\t");
printf("\tf.绝对值运算\n\t");
printf("\n\tg.数列运算(求和 平均值 标准差 方差)\n");
printf("\n\th.指数运算\t");
printf("\ti.求解一元二次方程\n");
printf("\n\tj.开方\t");
printf("\tk.三角函数\n");
printf("\n\tl.反三角函数\t");
printf("\tm.求自然对数\n");
printf("\n\tn.排列组合\n");
printf("\n输入任意键以返回选择界面");
}
void welcome()
{
printf("\n\n\t\t\t ********************");
printf("\n\t\t\t****欢**迎**使**用****");
printf("\n\t\t\t ********************");
printf("\n\t\t\t L A K E R S");
printf("\n\n");
}
void end()
{
printf("\n\n");
printf("********************************");
}
void endd()
{
printf("\n\n\t **************************************");
printf("\n\t***感 对 杉 湖 的 持*****");
printf("\n\t *****谢 洛 矶 人 支*******");
printf("\n\t****************************************");
printf("\n\t *********L A K E R S**************");
printf("\n\t****************************************");
}