- 论坛徽章:
- 0
|
这几天看<<c程序设计>;>;,我自己写了如下两段小程序:
- #include<stdio.h>;
- #include<math.h>;
- void main()
- {int x;
- char grade;
- scanf("%d\n",&x);
- if(90<=x<=100)grade='A';
- else if(80<=x<90)grade='B';
- else if(70<=x<80)grade='C';
- else if(60<=x<70)grade='D';
- else grade='E';
- printf("y=%c\n",grade);
- }
复制代码
和
- #include<stdio.h>;
- #include<math.h>;
- void main()
- {float a,b,c,disc,x1,x2,realpart,imagpart;
- scanf("%d,%d,%d",&a,&b,&c);
- printf("方程");
- if(fabs(a)<=1e-6)
- printf("无解");
- else
- {disc=b*b-4*a*c;
- if(fabs(disc)<=1e-6)
- printf("有两个相等的解:%8.4\n",-b/(2*a));
- else if(disc>;1e-6)
- {x1=(-b+sqrt(disc))/(2*a);
- x2=(-b-sqrt(disc))/(2*a);
- printf("有两个不相等的解:%8.4f和%8.4f\n",x1,x2);
- }
- else
- {realpart=-b/(2*a);
- imagpart=sqrt(-disc)/(2*a);
- printf("有两个不相等的复根:\n");
- printf("%8.4f+%8.4fi\n",realpart,imagpart);
- printf("%8.4f-%8.4fi\n",realpart,imagpart);
- }
- }
- }
复制代码
却发现了这样一个问题,程序通过编译,却不能得到我想要的结果,第一个程序想要的结果是:输入0~100内任意一个数字,得到输出属于不同等级的答案,可是老是得到grade=A这个答案,第二个程序也出现类似的错误,出现方程无解,这个答案,希望大家看看是怎么回事?指点一下?
还有warning C4804: '<=' : unsafe use of type 'bool' in operation
这句警告是什么意思啊,怎么排除掉,顺便也指点一下?
先谢谢各位大虾了! |
|