gpt4 book ai didi

c - 围绕圆计算点时输出不正确

转载 作者:太空宇宙 更新时间:2023-11-04 02:52:32 25 4
gpt4 key购买 nike

我在这个程序中没有得到正确的输出,我必须在给定圆心和圆半径的情况下计算输入的点是在圆内还是圆外还是在圆的边界上。它有时会给出正确答案,而有时则不会给出。例如,如果我输入 (0,0) 作为中心并设置 radius = 10 并检查点 (10,0) ,它表示该点位于圆外。不知道为什么会发生这种情况,因为在其他情况下检查它给出了正确的答案。这是程序的源代码 -

#include<stdio.h>

main()
{
float x1,y1,x2,y2,r,z;

printf("Please Enter The X And Y Coordinates Of The Centre Of The Circle = ");

scanf("%f%f",&x1,&y1);

printf("\nPlease Enter The Radius Of The Circle = ");

scanf("%f",&r);

printf("\nPlease Enter The Coordinates Of The Point You Want To Check");

scanf("%f%f",&x2,&y2);

z=x1*x1+x2*x2-2*x1*x2+y1*y1+y2*y2-2*y1*y2;

if(z*z==r*r)
printf("\nThe Point Entered Lies On The Boundary Of The Circle Described");

else if(z*z>r*r)
printf("\nThe Point Entered Is Outside The Circle Described");

else
printf("\nThe Point Entered Lies Inside The Circle");

}

最佳答案

改变条件

 if(z*z==r*r)  

 if(z==r*r)  

 else if(z*z>r*r)  

 else if(z>r*r)

因为 z 已经是您计算的两点之间距离的平方。

关于c - 围绕圆计算点时输出不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20620204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com