Created
March 26, 2020 05:35
-
-
Save paxbun/d3c3e09f77f0ea3eefd2007d799f8c36 to your computer and use it in GitHub Desktop.
5-7장 과제 정답 예시
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| int main() | |
| { | |
| int len = 0; | |
| double weights[5], heights[5]; | |
| int maxlen = sizeof weights / sizeof(double); | |
| printf("0: Add a member\n"); | |
| printf("Other than 0: Calculate BMI\n"); | |
| while (1) | |
| { | |
| printf(": "); | |
| int cmd; scanf("%d", &cmd); | |
| if (!cmd) | |
| { | |
| do | |
| { | |
| printf("Weight: "); | |
| scanf("%lf", weights + len); | |
| } while (weights[len] <= 0); | |
| do | |
| { | |
| printf("Height: "); | |
| scanf("%lf", heights + len); | |
| } while (heights[len] <= 0); | |
| ++len; | |
| if (len == maxlen) | |
| { | |
| break; | |
| } | |
| } | |
| else | |
| { | |
| break; | |
| } | |
| } | |
| if (!len) | |
| { | |
| printf("No output\n"); | |
| } | |
| else for (int i = 0; i < len; ++i) | |
| { | |
| int ord = i + 1; | |
| double weight = weights[i], height = heights[i], bmi = weight / (height * height / 10000); | |
| printf("\n%d", ord); | |
| if (ord == 1) | |
| printf("st"); | |
| else if (ord == 2) | |
| printf("nd"); | |
| else if (ord == 3) | |
| printf("rd"); | |
| else | |
| printf("th"); | |
| printf(" member\nWeight: %lf\nHeight: %lf\nBMI: %lf\n", weight, height, bmi); | |
| if (20 <= bmi && bmi < 25) | |
| printf("Good\n"); | |
| else | |
| printf("Bad\n"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment