For the following programs, you should run each of them using Dev-C++. You answe
ID: 3849483 • Letter: F
Question
For the following programs, you should run each of them using Dev-C++. You answer should include screen shots of your code and program outputs. Your programs should be properly commented. Problem 1 . Use C NOT C++.
Please includ the answer as a Text, so I can copy and paste it to test it.
Problem 3 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. QII QI QIV Qlll Sample lines of output: (-1.0, 2.5) is in quadrant III (0.0, 4.8) is on the y-axisExplanation / Answer
#include <stdio.h>
#include <math.h>
struct Point //structure
{
float x;
float y;
};
int quadrant(struct Point p) //quadrant function to determine the
quadrant in which point lies
{
if( p.x>0 && p.y>0)
return 1;
else if(p.x<0 && p.y>0)
return 2;
else if(p.x<0 && p.y<0)
return 3;
else if(p.x>0 && p.y<0)
return 4;
else
return 0;
}
int axis(struct Point p) //axis function to determine on which axis point lies
{
if(p.x == 0)
return 1;
else if(p.y == 0)
return 2;
else
return 0;
}
int main()
{
struct Point p1 = {-1.0, -2.5};
struct Point p2 = {0.0, 4.8};
printf("(%.1f,%.1f) is in quadrant %d",p1.x,p1.y,quadrant(p1));
printf(" ");
if(axis(p2) == 1)
printf("(%.1f,%.1f) is on y axis",p2.x,p2.y,axis(p2));
else if(axis(p2) == 2)
printf("(%.1f,%.1f) is on x axis",p2.x,p2.y,axis(p2));
else
printf(" ");
return 0;
}
Output:
(-1.0, -2.5) is in quadrant 3
(0.0, 4.8) is on the y-axis
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.