|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 xhtxhtxht 于 2023-1-25 15:33 编辑
请删帖。
代码如下
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int main(int argc,char * argv[])
- {
- if(argc == 1){
- printf("请输入一元二次方程的标准形式下的二次项系数,一次项系数和常数项!");
- return 0;
- }
- if(argc != 4){
- printf("输入的参数不符合规则!");
- exit(1);
- }
- int nums[4] = {0};
- for(int count = 0;count < 4;count++)
- nums[count] = atoi(argv[count + 1]);
- float delta;
- delta = nums[1] * nums[1] - 4 * nums[0] * nums[2];
- if(delta < 0){
- printf("无解!");
- return 0;
- }
- float x1,x2;
- x1 = (-nums[1] + sqrt(delta)) / (2 * nums[0]);
- x2 = (-nums[1] - sqrt(delta)) / (2 * nums[0]);
- printf("x1 = %.2f\nx2 = %.2f",x1,x2);
- return 0;
- }
复制代码
windows gcc正常编译,linuxgcc加-lm也可以,但是运行时段错误
改成 for int count = 0; count < 3; count++
|
|