Advertisement
a1ananth

c code

Dec 11th, 2011
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1. typedef struct {
  2.     int x;
  3.     int y;
  4. } vertex;
  5.  
  6. #include <stdio.h>
  7. #include <math.h>
  8.  
  9. void input(vertex *v) {
  10.     printf("\nEnter x-coordinate: ");
  11.     scanf("%d", &(v->x));
  12.     printf("\nEnter y-coordinate: ");
  13.     scanf("%d", &(v->y));
  14.  
  15.     return;
  16. }
  17.  
  18. double distance(vertex a, vertex b) {
  19.     double distance;
  20.     double x_diff = a.x - b.x;
  21.     double y_diff = a.y - b.y;
  22.  
  23.     distance = sqrt( (x_diff * x_diff) + (y_diff * y_diff));
  24.     return distance;
  25. }
  26.  
  27. int main() {
  28.     vertex a, b, c;
  29.     int temp = 1, flag= 0;
  30.     double d1, d2, d3;
  31.  
  32.     while(true) {
  33.         printf("\nEnter 1st vertex");
  34.         input(&a);
  35.         printf("\nEnter 2nd vertex");
  36.         input(&b);
  37.         printf("\nEnter 3rd vertex");
  38.         input(&c);
  39.  
  40.         d1 = distance(a, b);
  41.         d2 = distance(b, c);
  42.         d3 = distance(c, a);
  43.  
  44.         if ( ((d1*d1) + (d2*d2)) == (d3*d3) ) flag = 1;
  45.         if ( ((d3*d3) + (d2*d2)) == (d1*d1) ) flag = 1;
  46.         if ( ((d1*d1) + (d3*d3)) == (d2*d2) ) flag = 1;
  47.  
  48.         if (flag == 1) printf ("\n\nThe vertices you entered belong to a right angled triangle.\n");
  49.         else printf ("\n\nThe vertices you entered do not belong to a right angled triangle.\n");
  50.  
  51.         printf("Enter 1 to continue or 0 to exit: ");
  52.         scanf("%d", &temp);
  53.  
  54.         if (temp == 0) break;
  55.     }
  56.  
  57.     printf("\nThanks for using program.\n\n");
  58.     return 0;
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement