It is absolutely crucial to end all of your programs with: return 0; as the last
ID: 3629350 • Letter: I
Question
It is absolutely crucial to end all of your programs with:
return 0;
as the last line before the closing '}' bracket in your main function.
Programs that do not follow this convention will not be graded correctly.
Programs that end with that line may still fail because they do not
generate the right output.
Each sample run is indicated by a line of "=" symbols. These lines only indicate
the start and the end of a sample run and should not be printed by
your program.
Use 64-bit floating point numbers (i.e., double) for all floating
point calculations. Do not use float as your results may differ from the test cases
due to small precision errors.
Start with
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
(PLEASE, RUN YOUR PROGRAM BEFORE YOU SUBMIT TO MAKE SURE YOU HAVEA SAME RESULT THAT THIS PROBLEM HAS)
Problem 4
#########
Write a program that takes the x-y coordinates of a point in the Cartesian
plane and prints a message telling either an axis on which the point lies or
the quadrant in which it is found. If the point is at the origin, this should
be handled as well.
^
QII | QI
|
|
--------------+-------------->
|
|
|
QIII | QIV
Remarks: Please replicate the exact text of the prompts and the output. Make
sure that the numbers are printed with one digit precision (i.e., "%.1f" in
printf).Even though the prompts must be the same, the answer may be different
depending on the user input.
Remember that floating point zero can be signed. Please change negative zero
to positive when printing the numbers, but only when you are really dealing
with a negative zero. Infinities should be treated like numbers: inf is positive
and -inf is negative.
============= START OF SAMPLE RUN =======================
Enter the x and y coordinates of the point:
0 0
The point (0.0 0.0) is in the origin.
============= END OF SAMPLE RUN =======================
============= START OF SAMPLE RUN =======================
Enter the x and y coordinates of the point:
-0.00001 0
The point (-0.0 0.0) is on the x axis.
============= END OF SAMPLE RUN =======================
============= START OF SAMPLE RUN =======================
Enter the x and y coordinates of the point:
-0.0 0.00
The point (0.0 0.0) is in the origin.
============= END OF SAMPLE RUN =======================
============= START OF SAMPLE RUN =======================
Enter the x and y coordinates of the point:
-1 -2.5
The point (-1.0 -2.5) is in quadrant III.
============= END OF SAMPLE RUN =======================
============= START OF SAMPLE RUN =======================
Enter the x and y coordinates of the point:
0 4.8
The point (0.0 4.8) is on the y axis.
============= END OF SAMPLE RUN =======================
============= START OF SAMPLE RUN =======================
Enter the x and y coordinates of the point:
inf -inf
The point (inf -inf) is in quadrant IV.
============= END OF SAMPLE RUN =======================
Explanation / Answer
please rate - thanks
I started with the previous post and made changes.
it only allowed for (inf, -inf)
it would not allow any other combination of inf like (-inf,-inf)
I also got rid of the pointer which, my guess, you haven't learned yet
/*Header sectoin*/
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
/*main function*/
main()
{
/*declaring variables for point*/
double x,y;
char num1[10], num2[10]; //characters array to store input
printf("============= START OF SAMPLE RUN ======================= ");
/*prompting user for x and y*/
printf("Enter the x and y coordinates of the point: ");
/*reading*/
scanf("%s%s",num1,num2);
printf("The point (%s,%s) is ",num1,num2);
//checking for inf or -inf
if(strcmp(num1,"inf")==0)
x=1;
else if(strcmp(num1,"-inf")==0)
x=-1;
else
x=atoi(num1); //converts string to double
if(strcmp(num2,"inf")==0)
y=1;
else if(strcmp(num2,"-inf")==0)
y=-1;
else
y=atoi(num2); //converts string to double
/*if x and y are both zero's then point is in origin"*/
if(x==0&&y==0)
printf("on the origin ");
/*if x is zero's then point is on the y-axis"*/
else if(x==0)
printf("is on the y-axis ");
/*if x is zero's then point is on the y-axis"*/
else if(y==0)
printf("on the x-axis ");
else
{if(x>0)
{/*if x and y both are positive point in I quadrant*/
if(y>0)
printf("is in quadrant I ");
/*if x is positive and y is negative point in IV quadrant*/
else
printf("is in quadrant IV ");
}
else
{/*if y is positive and x is negative point in II quadrant*/
if(y>0)
printf("is in quadrant II ");
else
/*if x and y both are positive point in IV quadrant*/
printf("is in quadrant III ");
}
}
printf("============= END OF SAMPLE RUN ======================= ");
getch();/*to pause output*/
}/*end of main*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.