ExSeed books are very popular for school kids. ExSeed has now come out with an innovative idea of giving dynamic online practice quizzes.
Can you help them in solving one of their mathematical problems?
Given the coordinates of the center of the square (x,y) and the side of the square, find the coordinates of the 4 vertices of the square.
Assume that the side of the square is always even.
Input Format:
Input consists of 3 integers.
The 1st integer corresponds to the x-coordinate of the center of the square.
The 2nd integer corresponds to the y-coordinate of the center of the square.
The 3rd integer corresponds to the side of the square.
Output Format:
The output consists of 8 integers.
The first 2 integers correspond to the x and y coordinates the upper right corner of the square.
The next 2 integers correspond to the x and y coordinates the lower right corner of the square.
The next 2 integers correspond to the x and y coordinates the lower left corner of the square.
The next 2 integers correspond to the x and y coordinates the upper left corner of the square.
The x and y coordinates of each vertex should be printed on a separate line, separated by a, (comma).
Refer sample input and output for formatting specifications.
Sample Input:
7
6
4
Sample Output:
9,8
9,4
5,4
5,8
Program Code:
#include<stdio.h>
int main()
{
int x,y,z;
scanf("%d %d %d", &x, &y, &z);
z=z/2;
printf("%d,%d\n",x+z,y+z);
printf("%d,%d\n",x+z,y-z);
printf("%d,%d\n",x-z,y-z);
printf("%d,%d\n",x-z,y+z);
return 0;
}
Post A Comment:
0 comments: