31 Aralık 2012 Pazartesi

標準體重計算


已知男生標準體重=(身高-80 )*0.7;女生標準體重=(身高-70)*0.6;
試寫一個程式可以計算男生女生的標準體重。
並精確到小數點第二位
輸入說明:
輸入兩個數值,依序代表為身高及性別(1代表男性;2代表女性)。

輸出說明:
輸出標準體重。 

  1. #include <stdio.h>  
  2. #include <stdlib.h>  
  3.   
  4. int main(int argc, char *argv[])  
  5. {  
  6.     int sex,tall;  
  7.     double result;   
  8.     scanf("%d",&tall);  
  9.     scanf("%d",&sex);  
  10.     switch(sex){  
  11.               case 1:   
  12.                 result = (tall-80)*0.7;  
  13.                 printf("%.2f\n",result);  
  14.                 break;   
  15.               case 2:   
  16.                 result = (tall-70)*0.6;  
  17.                 printf("%.2f\n",result);  
  18.                 break;  
  19.               default:  
  20.                       printf("error\n");  
  21.                       break;   
  22.               }  
  23.               system("PAUSE");    
  24.   return 0;  
  25. }

Hiç yorum yok:

Yorum Gönder

Binary Conversion

Problem Description Convert two binary numbers into two decimal numbers and compute their sum. Your program has to convert two binary number...