身長と標準体重の対応表を表示するプログラム
printfとscanfもっとうまく書ける気がする。。
#include <stdio.h> int main(void){ int from,to,each; printf("何cmから:"); scanf("%d",&from); printf("%d\n",from); printf("何cmまで:"); scanf("%d",&to); printf("%d\n",to); printf("何cmごと:"); scanf("%d",&each); printf("%d\n",each); for(from; from <= to; from = from + each){ float stdWeight = (from - 100) * 0.9; printf("%dcm %0.2fkg\n",from,stdWeight); } }
入力
150 190 5
出力
何cmから:150 何cmまで:190 何cmごと:5 150cm 45.00kg 155cm 49.50kg 160cm 54.00kg 165cm 58.50kg 170cm 63.00kg 175cm 67.50kg 180cm 72.00kg 185cm 76.50kg 190cm 81.00kg