当前位置:编程学习 > C/C++ >>

c语言高手进

以下程序出错在哪里 # include<stdio.h> int main(void) { double a, b, c; double detal, x1, x2; do {printf("a = %lf", a); scanf("%lf", &a); printf("b = %df", b); scanf("%lf", &b); printf("c =%df", c); scanf("%lf", &c); detal = b*b-4*a*c; if (detal > 0) { x1 = (-b - sqrt(detal))/(2*a); x2 = (b - sqrt(detal))/(2*a); printf("有两个解: x1 = %fl,x2 = %fl", x1, x2); } else if (detal == 0) { x1 = x2 = (-b)/(2*a); printf("有一个解:x1 = x2 = %lf", x1, x2); } else printf("无解\n"); printf("你想继续么?Y/X"); scanf(" %c", &ch); } while('y' == ch || 'Y' == ch); return 0; }
答案:# include<stdio.h>
#include <math.h>//1未包括头文件math.h sqrt需要

int main(void)

{
	double a, b, c;

	double detal, x1, x2;
	
	char ch;//2未定义变量ch

   do {printf("a =");//3打印a变量的值没有意义

    scanf("%lf", &a);

	printf("b =");//3

    scanf("%lf", &b);

	printf("c =");//3

    scanf("%lf", &c);

	detal = b*b-4*a*c;
		if (detal > 0)

		{
			x1 = (-b - sqrt(detal))/(2*a);
		    x2 = (b - sqrt(detal))/(2*a);

			printf("有两个解: x1 = %fl,x2 = %fl\n", x1, x2);//缺少换行符,不算错

		}

		else if (detal == 0)

		{
			x1 = x2 = (-b)/(2*a);

		    printf("有一个解:x1 = x2 = %lf\n", x1, x2);//缺少换行符,不算错
		}


		else 

			printf("无解\n");


		printf("你想继续么?Y/X");

		scanf(" %c", &ch);
} while('y' == ch || 'Y' == ch);

return 0;

}
其他:第一题: #include

上一个:哪位C语言大侠能告诉我这个程序哪里有问题啊,为什么运行的结果没有,就见一光标在那闪啊!!
下一个:学过C语言,去学c++ 从什么开始学?

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,