| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1245 人关注过本帖
标题:哪位好人指导指导我
只看楼主 加入收藏
风雨晨曦
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2017-12-5
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
哪位好人指导指导我
能帮我看看这个程序哪错了吗,实在不懂我的错误在哪,谢谢大家了
#include <stdio.h>
#include <math.h>
int main(){
    float a,b,c,disc,x1,x2,p,q;
    printf("请输入二元一次方程的三个系数:");
    scanf("%d%d%d",&a,&b,&c);
    if(a==0){
        printf("二元一次方程的a不能为0");
        return;
    }
    disc=b*b-4*a*c;
    if(disc<0){
        printf("该二元一次方程无解");
        return;
    }
    p=-b/(2*a);
    q=sqrt(disc)/(2*a);
    x1=p+q;
    x2=p-q;
    printf("x1=%f\nx2=%f",x1,x2);
}
搜索更多相关主题的帖子: include printf 二元一次 方程 return 
2017-12-05 14:12
Jonny0201
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:52
帖 子:488
专家分:2603
注 册:2016-11-7
收藏
得分:20 
这个是我编译器里面的报错
总共三个错误
float 声明的时候应该用 %f 好像
第八行和第十三行最后的分号是中文分号
if 语句不需要 return,return 用在 void 里
改过的代码没有具体调试

Untitled.cpp:6:17: warning: format specifies type 'int *' but the argument has type 'float *' [-Wformat]
        scanf("%d%d%d",&a,&b,&c);
               ~~      ^~
               %f
Untitled.cpp:6:20: warning: format specifies type 'int *' but the argument has type 'float *' [-Wformat]
        scanf("%d%d%d",&a,&b,&c);
                 ~~       ^~
                 %f
Untitled.cpp:6:23: warning: format specifies type 'int *' but the argument has type 'float *' [-Wformat]
        scanf("%d%d%d",&a,&b,&c);
                   ~~        ^~
                   %f
Untitled.cpp:8:45: error: non-ASCII characters are not allowed outside of literals and identifiers
                printf("二元一次方程的a不能为0");
                                                ^~
Untitled.cpp:8:45: error: expected ';' after expression
                printf("二元一次方程的a不能为0");
                                                ^
                                                ;
Untitled.cpp:9:3: error: non-void function 'main' should return a value [-Wreturn-type]
                return;
                ^
Untitled.cpp:13:40: error: non-ASCII characters are not allowed outside of literals and identifiers
                printf("该二元一次方程无解");
                                            ^~
Untitled.cpp:13:40: error: expected ';' after expression
                printf("该二元一次方程无解");
                                            ^
                                            ;
Untitled.cpp:14:3: error: non-void function 'main' should return a value [-Wreturn-type]
                return;
                ^
3 warnings and 6 errors generated.


程序代码:
#include <stdio.h>
#include <math.h>
int main(){
    float a,b,c,disc,x1,x2,p,q;
    printf("请输入二元一次方程的三个系数:");
    scanf("%f%f%f",&a,&b,&c);
    if(a==0){
        printf("二元一次方程的a不能为0");
    }
    disc=b*b-4*a*c;
    if(disc<0){
        printf("该二元一次方程无解");
    }
    p=-b/(2*a);
    q=sqrt(disc)/(2*a);
    x1=p+q;
    x2=p-q;
    printf("x1=%f\nx2=%f",x1,x2);
}


[此贴子已经被作者于2017-12-5 14:25编辑过]

2017-12-05 14:20
风雨晨曦
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2017-12-5
收藏
得分:0 
回复 2楼 Jonny0201
真的万分感谢!
2017-12-05 14:30
快速回复:哪位好人指导指导我
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015394 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved