7-40 到底是不是太胖了(问题)
据说一个人的标准体重应该是其身高(单位:厘米)减去100、再乘以0.9所得到的公斤数。 真实体重与标准体重误差在10%以内都是完美身材(即 | 真实体重 − 标准体重 | < 标准体重×10%)。 已知市斤是公斤的两倍。现给定一群人的身高和实际体重,请你告诉他们是否太胖或太瘦了。 输入格式: 输入第一行给出一个正整数N(≤ 20)。随后N行,每行给出两个整数,分别是一个人的 身高H(120 < H < 200;单位:厘米)和真实体重W(50 < W ≤ 300;单位:市斤),其间以空格分隔。 输出格式: 为每个人输出一行结论:如果是完美身材,输出You are wan mei!;如果太胖了,输出You are tai pang le!;否则输出You are tai shou le!。 输入样例: 3 169 136 150 81 178 155 输出样例: You are wan mei! You are tai shou le! You are tai pang le!
#include<stdio.h> int main() { int height,N,i,t,k=0; double weight , standard_weight , up_weight , down_weight; int a[100]; scanf("%d",&N); for(i=1;i<=N;i++) { scanf("%d %f",&height,&weight); standard_weight=(height-100)*0.9; up_weight=standard_weight*1.1; down_weight=standard_weight*0.9; weight=weight/2.0; if(weight>down_weight&&weight<up_weight) { t=0; a[k]=t; k++; }else if(weight<down_weight){ t=1; a[k]=t; k++; }else{ t=2; a[k]=t; k++; } } int w=0; for(w=0;w<=k;w++) { if(a[w]==0) { printf("You are wan mei!\n"); }else if(a[w]==1){ printf("You are tai shou le!\n"); }else { printf("You are tai pang le!\n"); } } return 0; }
#include<stdio.h> int main(){ int n,a,b; double level,error; scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d %d",&a,&b); level=(a-100)*1.8; error=b-level; if(error < (level*0.1) && error > level*(-1)*0.1){ printf("You are wan mei!\n"); }else if(b > level){ printf("You are tai pang le!\n"); }else if(b < level){ printf("You are tai shou le!\n"); } } return 0; }
第 I 段——变量、表达式、分支、循环 文章被收录于专栏
中国大学MOOC 2021年春季C、Java入门练习第I段——变量、表达式、分支、循环