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
Post A Comment:
0 comments: