Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct {
- int x;
- int y;
- } vertex;
- #include <stdio.h>
- #include <math.h>
- void input(vertex *v) {
- printf("\nEnter x-coordinate: ");
- scanf("%d", &(v->x));
- printf("\nEnter y-coordinate: ");
- scanf("%d", &(v->y));
- return;
- }
- double distance(vertex a, vertex b) {
- double distance;
- double x_diff = a.x - b.x;
- double y_diff = a.y - b.y;
- distance = sqrt( (x_diff * x_diff) + (y_diff * y_diff));
- return distance;
- }
- int main() {
- vertex a, b, c;
- int temp = 1, flag= 0;
- double d1, d2, d3;
- while(true) {
- printf("\nEnter 1st vertex");
- input(&a);
- printf("\nEnter 2nd vertex");
- input(&b);
- printf("\nEnter 3rd vertex");
- input(&c);
- d1 = distance(a, b);
- d2 = distance(b, c);
- d3 = distance(c, a);
- if ( ((d1*d1) + (d2*d2)) == (d3*d3) ) flag = 1;
- if ( ((d3*d3) + (d2*d2)) == (d1*d1) ) flag = 1;
- if ( ((d1*d1) + (d3*d3)) == (d2*d2) ) flag = 1;
- if (flag == 1) printf ("\n\nThe vertices you entered belong to a right angled triangle.\n");
- else printf ("\n\nThe vertices you entered do not belong to a right angled triangle.\n");
- printf("Enter 1 to continue or 0 to exit: ");
- scanf("%d", &temp);
- if (temp == 0) break;
- }
- printf("\nThanks for using program.\n\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement