我刚开始学习c编程。程序检查点是否位于x轴,y轴或原点
对于这个问题,我写了下面的代码。你能帮我找到错误吗?我没有得到期望的结果,并且最后一个语句中的语句总是被执行。
#include<stdio.h>
#include<conio.h>
void dummy(float *a)
{
float b=*a; //perform some floating access
dummy (&b); //calling a floating point function
}
void main()
{
double x,y;
clrscr();
scanf("%lf %lf",x,y);
if(x==0 && y!=0)
{
printf("The point lies on the y-axis.");
}
else if(y==0 && x!=0)
{
printf("The point lies on the x-axis.");
}
else if(x==0 && y==0)
{
printf("The point is the origin");
}
else
{
printf("The point lies neither on the x nor the y axis ");
}
getch();
}
请编辑您的问题,包括输入导致的错误行为,以及实际和预期产出。 –
嗨。无论是我输入的2个数字,语句“该点既不在x也不在y轴上”被执行 –
这是当你不需要时发生的事情;不检查scanf的返回值。 –