Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void main(void)
{
//declaration
float x, y, distance, slope;
//intialization
printf("Enter the co-ordinates of point P (X , Y): ");
scanf("%f %f", &x, &y);
printf("\nThe point is ( %f , %f )", x, y);
//calculation
slope = y / x;
distance = sqrt( x * x + y * y);
if ( x = 0 )
{
printf("The slope is infinity!");
printf("The distance is %.2f", distance);
}
else
{
printf("\nThe slope is %.2f and the distance is %.2f",slope, distance);
}
exit( 0 );
} /* end main program */
Problem with the infinity part , the output shows 1.#J for some reason and I don't understand which part went wrong.
If X and Y are both numbers , the program seems to be working fine but if X = 0 , the problem just shows the slope output to be 1.#J instead of showing " The slope is infinity"