program for adding 2 points and checking whether a 3rd point lies in the area or not

1
File: /home/aditya/addpoint.c 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) // Function For Adding 2 points { int t,u; t=p+q; u=r+s; printf("\nThe added points are %d and %d \n",t,u); return 0; } float dist(int a, int b,int c,int d) // Function for finding the distance between 2 points { float temp1,temp2,sum,temp3; temp1=(a-c)*(a-c); temp2=(b-d)*(b-d); sum=temp1+temp2; temp3=sqrt(sum); return temp3; } 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; }

Upload: aditya-krishnakumar

Post on 23-Dec-2015

217 views

Category:

Documents


5 download

DESCRIPTION

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)

TRANSCRIPT

Page 1: Program for Adding 2 Points and Checking Whether a 3rd Point Lies in the Area or Not

File: /home/aditya/addpoint.c 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) // Function For Adding 2 points{int t,u;t=p+q;u=r+s;printf("\nThe added points are %d and %d \n",t,u);return 0;}

float dist(int a, int b,int c,int d) // Function for finding the distance between 2 points{float temp1,temp2,sum,temp3;temp1=(a-c)*(a-c);temp2=(b-d)*(b-d);sum=temp1+temp2;temp3=sqrt(sum);return temp3;}

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;}