救命。我的错误在哪里? [英] Help. Where is my error?

查看:84
本文介绍了救命。我的错误在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是自学C学生。我陷入了二次方程式下面的程序,如果有人能帮助我解开这个谜团,我将非常感激。

为什么计算机拒绝执行我的scanf(%c,& amp; ; q);

输入3 4 1(对于a,b和c)我有真正的根源确定

输入1 8 16我有同样的真实根源。


但是在4 2 5,(对于想象的根),计算机看不到scanf(%c,& q);声明。它只是跳过它。

如何让电脑不要忽视这个陈述?我在Visual C ++平台上。

谢谢

Khoon。


/ *二次方程的根。

12.10.05 * /


#include< stdio.h>

#include< stdlib.h>

#include< math.h>


int main(无效)


{

int a; int b; int c; float x1; float x2; int E; int E1;漂浮R;漂浮我;漂浮S;

char p; char q; char;


printf("请键入常量a,b和c的值以查找二次曲线的根);

printf( 方程ax%c + bx + c = 0:,253);

scanf(%d%d%d,& a,& b,& c );


E =(b * b) - (4 * a * c);


if(E> 0)

{

x1 =(浮动)( - b + sqrt(E))/(2 * a);

x2 =(浮动) (-b-sqrt(E))/(2 * a);


printf(" \ n你的二次方程有两个截然不同的实根:x1 =%1.6f,x2 =%1.6f",x1,x2);

}


else if(E == 0)

{


x1 =(浮动)( - b + sqrt(E))/(2 * a);


printf(" \你的二次方程有两个相同:x1 = x2 =%1.6f \ n,x1);

}


其他

$

p =''y'';


printf("你的二次方程有两个截然不同的假想根。你想要吗?知道\ n;

printf (虚根(Y / N)的值?);


scanf("%c"& q);


printf(" \\\
q =%c \ n",q); / *测试声明* /


if(p == q)

printf(好的,我明天会显示你想象的根源。\ n);


else

printf( Good bye \ n;)


返回0;


}

}

解决方案



" Red Dragon" < TS ***** @ streamyx.com>写在留言

新闻:43 ******** @ news.tm.net.my ...
我是自学C学生。我在下面的方案中遇到了二次
等式,如果有人能帮我解开

之谜,我将非常感激。为什么计算机拒绝执行我的scanf(& ;%c"& q);
在输入3 4 1(对于a,b和c)我有真正的根源确定
在输入1 8 16我有相同的真实根源。
但是在4 2 5,(假想的根)计算机看不到
scanf(%c,& q); >语句。它只是跳过它。我怎么能让电脑不要忽视这个陈述?我在Visual
C ++平台上。谢谢
Khoon。
/ *二次方程的根。
12.10.05 * /
#include< stdio.h>
#include< stdlib.h>
#包括< math.h>
int main(void)
{
int a; int b; int c; float x1; float x2; int E; int E1;漂浮R; float
I; float S; char p; char q; char y;
printf(请输入常数a,b和c的值,以找到二次方的
根); printf(equation ax%c + bx + c = 0:,253);
scanf(%d%d%d,& a,& b,& c);
E =(b * b) - (4 * a * c);
if(E> 0)
{
x1 =(float)( - b + sqrt(E))/(2 * a);
x2 =(float) (-b-SQRT(E))/(2 * A);
printf(" \ n你的二次方程有两个截然不同的实根:x1 =%1.6f
,x2 =%1.6f",x1,x2); }
else if(E == 0)
{
x1 =(float)( - b + sqrt(E))/(2 * a);
printf(" \ n你的二次方程有两个相同:x1 = x2 =%1.6f \ n,x1);
}
else
{
p =''y'';
printf("你的二次方程有两个截然不同的假根。你想要知道'
'); printf(虚根(Y / N)的值?);


/ ************************************* ************* ******

fflush(stdin);

/ ********* ***************************************** ****** scanf(" ;%C",&安培; q);
printf(" \ nq =%c \ n",q); / *测试声明* /



/ snip>


在文章< dj ********* @ blackmamba.itd.rl.ac.uk>,

Geoff Turner< g。** ******@rl.ac.uk>写道:

fflush(stdin);




不! fflush()在输入流上没有定义的行为!!


-

我是垃圾邮件,因此我是。


文章< 43 ******** @ news.tm.net.my>,

红龙< ts ***** @ streamyx.com>写道:

我是自学C学生。我在下面的程序中遇到了二次方程式,如果有人能帮助我解开这个谜团,我将非常感激。
为什么计算机拒绝执行我的scanf(&%; c",& q);




我们大约每隔一天进行一次这一点,在FAQ中肯定是




我在一周前的解释可以在
http://groups.google.ca/group/comp.l...65f0744a89f300


-

有什么事可以说,看,这是新的吗?它已经过时了,这已经是我们面前的了。 - 传道书


I am self study C student. I got stuck in the program below on quadratic equation and will be most grateful if someone could help me to unravel the mystery.
Why does the computer refuse to execute my scanf ("%c",&q);
On input 3 4 1 (for a,b and c) I had real roots OK
On input 1 8 16 I had same real roots OK.

However on 4 2 5, (for imaginary roots ) the computer cannot see the scanf ("%c",&q); statement. It just jumps over it.
How can I make the computer not to ignore this statement? I am on Visual C++ platform.
Thanks
Khoon.

/* Roots of a Quadratic Equation.
12.10.05 */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main (void)

{
int a; int b; int c; float x1; float x2; int E; int E1; float R; float I;float S;
char p; char q; char y;

printf ("Please key in the value of constant a,b and c for finding the roots of quadratic");
printf ("equation ax%c+bx+c=0 :",253);
scanf ("%d%d%d", &a,&b,&c);

E =(b*b)-(4*a*c);

if ( E > 0)
{
x1 = (float)(-b+sqrt(E))/(2*a);
x2 = (float)(-b-sqrt(E))/(2*a);

printf ("\nYour quadratic equation has two distinct real roots: x1=%1.6f ,x2=%1.6f",x1,x2);
}

else if (E == 0)
{

x1 = (float)(-b+sqrt(E))/(2*a);

printf ("\nYour quadratic equation has two same: x1=x2=%1.6f\n",x1);
}

else
{

p = ''y'';

printf ("Your quadratic equation has two distinct imaginary roots. Do you want to know\n");
printf ("the values of the imaginary roots (Y/N)?");

scanf ("%c",&q);

printf ("\nq = %c\n",q);/* Test statement*/

if (p==q)
printf ("OK I will show your the imaginary roots tomorrow.\n");

else
printf ("Good bye\n");

return 0;

}
}

解决方案


"Red Dragon" <ts*****@streamyx.com> wrote in message

news:43********@news.tm.net.my...
I am self study C student. I got stuck in the program below on quadratic equation and will be >most grateful if someone could help me to unravel the
mystery.Why does the computer refuse to execute my scanf ("%c",&q);
On input 3 4 1 (for a,b and c) I had real roots OK
On input 1 8 16 I had same real roots OK. However on 4 2 5, (for imaginary roots ) the computer cannot see the scanf ("%c",&q); >statement. It just jumps over it.How can I make the computer not to ignore this statement? I am on Visual C++ platform.Thanks
Khoon. /* Roots of a Quadratic Equation.
12.10.05 */ #include <stdio.h>
#include <stdlib.h>
#include <math.h> int main (void) {
int a; int b; int c; float x1; float x2; int E; int E1; float R; float I;float S;char p; char q; char y; printf ("Please key in the value of constant a,b and c for finding the roots of quadratic"); printf ("equation ax%c+bx+c=0 :",253);
scanf ("%d%d%d", &a,&b,&c); E =(b*b)-(4*a*c); if ( E > 0)
{
x1 = (float)(-b+sqrt(E))/(2*a);
x2 = (float)(-b-sqrt(E))/(2*a); printf ("\nYour quadratic equation has two distinct real roots: x1=%1.6f ,x2=%1.6f",x1,x2); } else if (E == 0)
{ x1 = (float)(-b+sqrt(E))/(2*a); printf ("\nYour quadratic equation has two same: x1=x2=%1.6f\n",x1);
} else
{ p = ''y''; printf ("Your quadratic equation has two distinct imaginary roots. Do you want to know\n"); printf ("the values of the imaginary roots (Y/N)?");
/************************************************** ******
fflush (stdin );
/************************************************** ****** scanf ("%c",&q); printf ("\nq = %c\n",q);/* Test statement*/


/snip>


In article <dj*********@blackmamba.itd.rl.ac.uk>,
Geoff Turner <g.********@rl.ac.uk> wrote:

fflush (stdin );



No! fflush() has no defined behaviour on an input stream!!

--
I am spammed, therefore I am.


In article <43********@news.tm.net.my>,
Red Dragon <ts*****@streamyx.com> wrote:

I am self study C student. I got stuck in the program below on
quadratic equation and will be most grateful if someone could help me to
unravel the mystery.
Why does the computer refuse to execute my scanf ("%c",&q);



We go through this about every second day, and it is surely
in the FAQ.

My explanation of a week ago can be found at
http://groups.google.ca/group/comp.l...65f0744a89f300

--
Is there any thing whereof it may be said, See, this is new? It hath
been already of old time, which was before us. -- Ecclesiastes


这篇关于救命。我的错误在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆