程式找出點相對于輸入圓心和半徑的圓的位置。我想出了下面給出的代碼,但由于某種原因,只有第一個 printf 和 scanf 陳述句被執行,其余的陳述句被忽略。
//point wrt a circle
#include <stdio.h>
#include <math.h>
int main(){
//input radius and centre
float r,x,y,f,g,d;
printf("Enter centre's x,y and radius: ");
scanf("%f%f%f",&f,g,&r);
printf("enter the x y of the point");
scanf("%f%f",&x,&y);
//formula for distance
d=pow(pow((x-f),2) pow((y-g),2),0.5);
//comparing d with r
if (r==d)
printf("on the circle");
else if(r<d)
printf("outside the circle");
else
printf("Inside the circle");
return 0;
}
終端要求我輸入半徑和中心的坐標,就是這樣!請幫助我了解我的代碼有什么問題。
uj5u.com熱心網友回復:
scanf("%f%f%f",&f,g,&r);
應該:
scanf("%f%f%f",&f,&g,&r);
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/359871.html
標籤:C
上一篇:C中的一維和二維陣列
