标题:再次[求助]我看不出来有什么错误????
只看楼主
zglcx123
Rank: 2
等 级:论坛游民
帖 子:60
专家分:10
注 册:2007-7-2
 问题点数:0 回复次数:3 
再次[求助]我看不出来有什么错误????

//计算二次方程的根
#include <stdio.h>

int a, b, c;
float x1, x2, data;


int main (void)
{
float todata ( float data);//检验data 的正负 以确定有没有实数根
float sqrt ( float n);//计算二次方的函数

printf ("输入二次方程的a b c:\n");
printf ("a = ");
scanf ("%i", &a);

printf ("b = ");
scanf ("%i", &b);

printf ("c = ");
scanf ("%i", &c);

printf ("方程是: %ix^ + %ix + %i = 0 \n", a , b , c);

data = (float)b * b - 4 * a * c;
data = todata ( data );//检验data的正负

x1 = (-b + sqrt ( data )) / ( 2 * a );
x2 = (-b - sqrt ( data )) / ( 2 * a );

printf ("x1 = %i \nx2 = %i\n", x1, x2);

return 0;
}

float todata ( float data)
{
if ( data < 0)
{
printf ("根是复数\n");
}
else
data = data ;
return 0;
}

float sqrt ( float n)//计算二次方的函数
{
float guess = 1;
const double epsilon = 0.00001;

while ( n / ( guess * guess ) - 1 >= epsilon )
guess = ( n / guess + guess ) / 2;

return guess;
}

搜索更多相关主题的帖子: 检验 include 
2007-07-11 18:16
zglcx123
Rank: 2
等 级:论坛游民
帖 子:60
专家分:10
注 册:2007-7-2
得分:0 

错了,
再次[求助]我看不出来有什么错误????//计算二次方程的根
#include <stdio.h>

int a, b, c;
float x1, x2, data;


int main (void)
{
float todata ( float data);//检验data 的正负 以确定有没有实数根
float sqrt ( float n);//计算二次方的函数

printf ("输入二次方程的a b c:\n");
printf ("a = ");
scanf ("%i", &a);

printf ("b = ");
scanf ("%i", &b);

printf ("c = ");
scanf ("%i", &c);

printf ("方程是: %ix^ + %ix + %i = 0 \n", a , b , c);

data = (float)b * b - 4 * a * c;
data = todata ( data );//检验data的正负

x1 = (-b + sqrt ( data )) / ( 2 * a );
x2 = (-b - sqrt ( data )) / ( 2 * a );

printf ("x1 = %f \nx2 = %f\n", x1, x2);//%i 该为%f

return 0;
}

float todata ( float data)
{
if ( data < 0)
{
printf ("根是复数\n");
}
else
data = data ;
return 0;
}

float sqrt ( float n)//计算二次方的函数
{
float guess = 1;
const double epsilon = 0.00001;

while ( n / ( guess * guess ) - 1 >= epsilon )
guess = ( n / guess + guess ) / 2;

return guess;
}

2007-07-11 18:24
huangfengchu
Rank: 1
等 级:新手上路
威 望:2
帖 子:274
专家分:0
注 册:2007-5-22
得分:0 

晕,还没看清楚!啊,就是这里。应该返回DATA;但你返回了0;
float todata ( float data)
{
if ( data < 0)
{
printf ("根是复数\n");
}
else
data = data ;
return 0;
}

[此贴子已经被作者于2007-7-11 18:36:51编辑过]


深山苦学C语言,终年不见外面世界。
2007-07-11 18:26
zglcx123
Rank: 2
等 级:论坛游民
帖 子:60
专家分:10
注 册:2007-7-2
得分:0 

#include <stdio.h>

int a, b, c;
float x1, x2, data;


int main (void)
{
float todata ( float data);//检验data 的正负 以确定有没有实数根
float sqrt ( float n);//计算二次方的函数

printf ("输入二次方程的a b c:\n");
printf ("a = ");
scanf ("%i", &a);

printf ("b = ");
scanf ("%i", &b);

printf ("c = ");
scanf ("%i", &c);

printf ("方程是: %ix^ + %ix + %i = 0 \n", a , b , c);

data = (float)b * b - 4 * a * c;
data = todata ( data );//检验data的正负

x1 = (-b + sqrt ( data )) / ( 2 * a );
x2 = (-b - sqrt ( data )) / ( 2 * a );

printf ("x1 = %f \nx2 = %f\n", x1, x2);

return 0;
}

float todata ( float data)
{
if ( data < 0)
{
printf ("根是复数\n");
}
else
data = data ;
return data;
}

float sqrt ( float n)//计算二次方的函数
{
float guess = 1;
const double epsilon = 0.00001;//精度

while ( n / ( guess * guess ) - 1 >= epsilon )
guess = ( n / guess + guess ) / 2;

return guess;
}
还是不对呀 计算出来的答案有误
你们帮我看一下函数的调用 看有没有错

2007-07-11 20:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-154701-1-1.html




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

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