Advertisement
Guest User

埃及三角形

a guest
Sep 21st, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main() {
  5.   int a, b, c;
  6.  
  7.   while (scanf("%d %d %d", &a, &b, &c)==3 && (a || b || c)) {
  8.       // scanf 函數本身會回傳「輸入成功」的元素數量,驗證==3會確保輸入結束的時候迴圈也會結束
  9.       // a || b || c 就是 a != 0 && b != 0 && c != 0 的意思
  10.     if (a > b && a > c) {
  11.       if (a * a == b * b + c * c) {
  12.         printf("right\n");
  13.       } else {
  14.         printf("wrong\n");
  15.       }
  16.     } else if (c > a && c > b) {
  17.       if (c * c == a * a + b * b) {
  18.         printf("right\n");
  19.       } else {
  20.         printf("wrong\n");
  21.       }
  22.     } else if (b > a && b > c) {
  23.       if (b * b == c * c + a * a) {
  24.         printf("right\n");
  25.       } else {
  26.         printf("wrong\n");
  27.       }
  28.     } else
  29.         printf("wrong\n"); // 有可能是 eg. 2 2 2 等合法的三角形按照原本的狀況會直接 return 0 結束程式而不輸出東西,正確應為 print wrong
  30.   }
  31.  
  32.   return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement