Wednesday 9 March 2016

PLACING THE FLAG POST


The shape of the college ground is Square. For the Independence day Flag Hoisting Function, it has been decided to place the flag post at the exact center of the ground. Can you please help them in placing the flag post at the exact centre?

Given the coordinates of the left bottom vertex of the square ground and the length of the side, you need to write a program to determine the coordinates of the centre of the ground.

[Assumption --- Length of the side is always even]

Input Format:

Input consists of 3 integers. The first integer corresponds to the x-coordinate of the left bottom vertex. The second integer corresponds to the y-coordinate of the left bottom vertex. The third integer corresponds to the length of the square.

Output Format:

Refer Sample Input and Output for exact formatting specifications.


Sample Input and Output:

[All text in bold corresponds to input and the rest corresponds to output]
Enter the x-coordinate of the left bottom vertex
4
Enter the y-coordinate of the left bottom vertex
0
Enter the length of a side
8
The centre of the ground is at (8,4)

Code:
  #include<stdio.h>
int main(){
  int x,y,l;
  char s='(';
  char ss=')';
  
  printf("Enter the x-coordinate of the left bottom vertex\n");
  scanf("%d",&x);
  printf("Enter the y-coordinate of the left bottom vertex\n");
  scanf("%d",&y);
  printf("Enter the length of a side\n");
  scanf("%d",&l);
  x=x+(l/2);
  y=y+(l/2);
  printf("The centre of the ground is at %c%d,%d%c",s,x,y,ss);
  return 0;
}

1 comment:

  1. can you please explain the logic how it will be..........

    ReplyDelete