Home > Blockchain >  Position of a point as seen by a circle
Position of a point as seen by a circle

Time:11-18

Program to find out position of the point with respect to a circle whose centre and radius are input. I came up with the code given below, but for some reason only the first printf and scanf statements are executed and rest of the statements are ignored.

//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;
}

Terminal asks me to input the radius and centre's coordinates and that's it! Please help me understand what's wrong with my code.

CodePudding user response:

scanf("%f%f%f",&f,g,&r);

should be:

scanf("%f%f%f",&f,&g,&r);
  •  Tags:  
  • c
  • Related