Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main() {
- int a, b, c;
- while (scanf("%d %d %d", &a, &b, &c)==3 && (a || b || c)) {
- // scanf 函數本身會回傳「輸入成功」的元素數量,驗證==3會確保輸入結束的時候迴圈也會結束
- // a || b || c 就是 a != 0 && b != 0 && c != 0 的意思
- if (a > b && a > c) {
- if (a * a == b * b + c * c) {
- printf("right\n");
- } else {
- printf("wrong\n");
- }
- } else if (c > a && c > b) {
- if (c * c == a * a + b * b) {
- printf("right\n");
- } else {
- printf("wrong\n");
- }
- } else if (b > a && b > c) {
- if (b * b == c * c + a * a) {
- printf("right\n");
- } else {
- printf("wrong\n");
- }
- } else
- printf("wrong\n"); // 有可能是 eg. 2 2 2 等合法的三角形按照原本的狀況會直接 return 0 結束程式而不輸出東西,正確應為 print wrong
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement