0% found this document useful (0 votes)
71 views1 page

Program For Adding 2 Points and Checking Whether A 3rd Point Lies in The Area or Not

This is my program for 3 c programs... this program is for adding 2 points and checking a third point lies in the area of rectangle or not. I have used structures in this program (also functions)
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views1 page

Program For Adding 2 Points and Checking Whether A 3rd Point Lies in The Area or Not

This is my program for 3 c programs... this program is for adding 2 points and checking a third point lies in the area of rectangle or not. I have used structures in this program (also functions)
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

File: /home/aditya/addpoint.

Page 1 of 1

#include<stdio.h>
#include<math.h>
struct point
{
int x;
int y;
float area;
}p1,p2,p3,p4;
int addpoint(int, int, int, int);
float dist(int, int, int, int);
float ptinrect(int, int, float);
main()
{
int g,h;
float area1;
printf("Enter the 2D co-ordinates of point 1 : ");
scanf("%d %d",&p1.x,&p1.y);
printf("\nEnter the 2D co-ordinates of point 2 : ");
scanf("%d %d",&p2.x,&p2.y);
addpoint(p1.x,p2.x,p1.y,p2.y);
printf("\n The area of the rectangle is calculated using 3 points \n");
printf("Enter the 2D co-ordinates of point 3 : ");
scanf("%d %d",&p3.x,&p3.y);
g=dist(p1.x,p1.y,p2.x,p2.y);
h=dist(p2.x,p2.y,p3.x,p3.y);
area1=g*h;
printf("\nArea of the 3 points (%d,%d)(%d,%d) and (%d,%d) is %f",p1.x,p1.y,p2.x,p2.y,p3.x,p3.y,area1);
printf("\n Enter the co-ordinate to be checked whether it lies in the area or not : ");
scanf("%d %d",&p4.x,&p4.y);
ptinrect(p4.x,p4.y,area1);
}
int addpoint(int p, int q, int r, int s)
{
int t,u;
t=p+q;
u=r+s;
printf("\nThe added points are %d and %d \n",t,u);
return 0;
}

// Function For Adding 2 points

float dist(int a, int b,int c,int d)


points
{
float temp1,temp2,sum,temp3;
temp1=(a-c)*(a-c);
temp2=(b-d)*(b-d);
sum=temp1+temp2;
temp3=sqrt(sum);
return temp3;
}

// Function for finding the distance between 2

float ptinrect(int m,int n,float o)


// Function for checking whether entered 4th
point lies in the rectangle or not.. (Area from 3 previously entered points...)
{
float f;
if(m>(p2.x+p3.x) || n>(p2.y+p3.y))
{printf("\n The point (%d,%d) DOES NOT LIE in the area of 3 entered points (AREA = %f)\n",m,n,o);}
else
{printf("\n The point (%d,%d) LIES in the area of 3 entered points (AREA = %f)\n",m,n,o);}
return 0;
}

You might also like