Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Position of a point as seen by a circle

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

should be:

scanf("%f%f%f",&f,&g,&r);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading