Friday 3 June 2016

Write a program that prompts the user for Cartesian coordinates of two points x1, y1, x2, y2 and displays the distance between them. Write a function distance() with input four parameters to compute the distance. The function returns distance to the calling function.

#include<iostream.h>
#include<conio.h>
#include<math.h>
float Distance(int , int , int , int);
void main()
{
      clrscr();
      int cx1, cy1, cx2, cy2;
      float result;
      cout<<"Enter coordinates of  first point: ";
      cin>>cx1>>cy1;
      cout<<"Enter coordinates of second point: ";
      cin>>cx2>>cy2;
      reult = Distance (cx1, cy1,cx2,cy2);
      cout<<"The distance between given point is : "<<result;
      getch();
}

float Distance(int x1,int y1, int x2, int y2)
{
      return sqrt(pow(x2-x1),2)+pow((y2-y1),2));
}
Share:

0 comments:

Post a Comment

Popular Posts

Recent Posts

Unordered List

Text Widget

Pages

About Me

My photo
A group of two, with a little hope of helping beginners to learn how to code :)
Powered by Blogger.

Comments

Facebook

Ad Home

Follow Us

Random Posts

Sponsor

Recent Posts

Header Ads

Popular Posts

Copyright © Functions in C++ | Powered by Blogger

Design by ThemePacific | Blogger Theme by NewBloggerThemes.com | Distributed By Blogger Templates20