Write a program that uses co-ordinate to model a point.



Implementation of the above problem in C++:
#include<iostream>
using namespace std;
#define N 2
struct point
{
int x;
int y;
}
p[N],pt={0,0};
int main()
{
int i;
for(i=0;i<=N-1;i++)
{
cout<<"Enter coordinates x"<<i+1<<" & y"<<i+1<<":";
cin>>p[i].x>>p[i].y;
cout<<endl;
}
for(i=0;i<=N-1;i++)
{
pt.x=pt.x+p[i].x;
pt.y=pt.y+p[i].y;
}
cout<<"sum of "<<N<<" points is:"<<pt.x<<","<<pt.y;
return 0;
}


The output of the above program is tested on www.jdoodle.com
Output:
Enter coordinates x1 & y1: 12  24
Enter coordinates x2 & y2: 13  27
sum of 2 points is:25,51


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: