| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 552 人关注过本帖
标题:求函数的解(麻烦谁帮忙改一下)
只看楼主 加入收藏
wang6969772
Rank: 2
来 自:陕西西安
等 级:论坛游民
帖 子:11
专家分:10
注 册:2014-10-26
结帖率:25%
收藏
已结贴  问题点数:20 回复次数:3 
求函数的解(麻烦谁帮忙改一下)
#include<stdio.h>
#include<math.h>
float DaYu(int a,int b,int c);
float XiaoYu(int a,int b,int c);
float DengYu(int a,int b,int c);
int main()
{
    int m,n,l;
    float x1,x2,t,result;
    printf("qing shu ru m(m!=0),n,l:\n");
    scanf("%d,%d,%d",&m,&n,&l);
    t=n*n-4*m*n;
    if(t>0)
    {
        result=DaYu(m,n,l);
        printf("%.2f,%.2f",x1,x2);
    }
    else if(t<0)
    {
        result=XiaoYu(m,n,l);
        printf("wujie");
    }
    else
    {
        result=DengYu(m,n,l);
        printf("%.2f",x1);
   
    return 0;

}
float DaYu(int a,int b,int c)
{
    float x1,x2,t;
    x1=(-b+sqrt(t))/(2*a);
    x2=(-b-sqrt(t))/(2*a);
    return x1,x2;
}

float XiaoYu(int a,int b,int c)
{
    printf("wujie");
}
float DengYu(int a,int b,int c)
{
    float x1;
    x1=-b/2a;
}
错误:
test37.cpp
F:\c 源代码\test37\test37.cpp(12) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
F:\c 源代码\test37\test37.cpp(32) : error C2601: 'DaYu' : local function definitions are illegal
F:\c 源代码\test37\test37.cpp(40) : error C2601: 'XiaoYu' : local function definitions are illegal
F:\c 源代码\test37\test37.cpp(44) : error C2601: 'DengYu' : local function definitions are illegal
F:\c 源代码\test37\test37.cpp(46) : error C2059: syntax error : 'bad suffix on number'
F:\c 源代码\test37\test37.cpp(48) : fatal error C1004: unexpected end of file found
搜索更多相关主题的帖子: include result 
2014-12-07 12:20
zkcok
Rank: 1
等 级:新手上路
帖 子:3
专家分:7
注 册:2014-12-7
收藏
得分:7 
这个代码是行不通的。我就帮你把编译的错误改了,不过结果还是错的,方法的问题
#include<stdio.h>
#include<math.h>
float DaYu(float a,float b,float c);
float XiaoYu(float a,float b,float c);
float DengYu(float a,float b,float c);
int main()
{
    int m,n,l;
    float x1,x2,t,result;
    printf("qing shu ru m(m!=0),n,l:\n");
    scanf("%d,%d,%d",&m,&n,&l);
    t=n*n-4*m*l;
    if(t>0)
    {
        result=DaYu(m,n,l);
        printf("%.2f,%.2f",x1,x2);
    }
    else if(t<0)
    {
        result=XiaoYu(m,n,l);
    }
    else
    {
        result=DengYu(m,n,l);
        printf("%.2f",x1);
    }
   
    return 0;

}
float DaYu(float a,float b,float c)
{
    float x1,x2,t;
    x1=(-b+sqrt(t))/(2*a);
    x2=(-b-sqrt(t))/(2*a);
    return x1,x2;
}

float XiaoYu(float a,float b,float c)
{
    printf("wujie");
}
float DengYu(float a,float b,float c)
{
    float x1;
    x1=-b/2*a;
}
2014-12-07 16:51
pauljames
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:千里冰封
威 望:9
帖 子:1555
专家分:10000
注 册:2011-5-8
收藏
得分:7 
自己单步跟跟看

经常不在线不能及时回复短消息,如有c/单片机/运动控制/数据采集等方面的项目难题可加qq1921826084。
2014-12-07 21:54
yahwei
Rank: 7Rank: 7Rank: 7
来 自:湖~
等 级:黑侠
威 望:3
帖 子:145
专家分:644
注 册:2011-11-10
收藏
得分:7 
回复 楼主 wang6969772
为了分数,给出代码:
程序代码:
#include<stdio.h>
#include<math.h>
int main(void)
{
    int a,b,c;
    double t;
    printf("qing shu ru a(a!=0),b,c:");
    scanf("%d,%d,%d",&a,&b,&c);
    t = b * b - 4.0 * a* c;
    if ( t > 0 )
    {
        printf( "x1 = %.2f,x2 = %.2f\n", (0-b+sqrt(t))/2.0*a, (0-b-sqrt(t))/2.0*a );
    }
    else if( t < 0 )
    {
        printf( "wujie\n" );
    }
    else
    {
        printf( "x1 = x2 = %.2f\n", (0-b)/2.0*a );
    }
    return 0;
}


另外,给个最真诚的建议,回去好好看基础书,入门书……
下次再写出那样的代码就有找骂的嫌疑了。

[qq]949654600[/qq]
2014-12-08 14:18
快速回复:求函数的解(麻烦谁帮忙改一下)
数据加载中...
 
   



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

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