31 Aralık 2012 Pazartesi

判斷基數偶數


輸入說明:
輸入一個整數

輸出說明:
輸出奇數或偶數

  1. #include <stdio.h>  
  2. #include <stdlib.h>  
  3.   
  4. int main(int argc, char *argv[])  
  5. {  
  6.     int a;   
  7.       
  8. scanf("%d",&a);       
  9.     if(a%2==0){  
  10.                printf("even\n");   
  11.                }  
  12.                else  
  13.                printf("odd\n");  
  14.                
  15.   system("PAUSE");    
  16.   return 0;  
  17. }  

標準體重計算


已知男生標準體重=(身高-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. }

羅馬數字轉換


Write a program to convert positive integers into Roman numbers. 
The rule for constructing a Roman number is assumed to be as follows. 
In Roman number system, i is the symbol for 1, v for 5, x for 10, l for 50, 
c for 100, d for 500 and m for 1000. 
Symbols with larger values usually appear before symbols with smaller values. 
The value of a Roman number is, in general, the sum of the values of the symbols. 
For example, ii is 2, viii is 8. However, 
if a symbol with smaller value appears before a symbol with larger value, 
the value of these two symbols is the difference of the two values. 
For example, iv is 4, ix is 9, and lix is 59. 
Note that no four consecutive symbols in the Roman number can be the same. 
For example, iv, but not iiii, is the Roman number 4. 

hint:羅馬數值表,本測資參照http://wywu.pixnet.net/blog/post/23023232。

本題禁止使用迴圈。

The Input

輸入為一個正整數,並且小於100

The Output

根據輸入的整數,輸出對應的羅馬數字

Sample Input

3

Sample Output

III

  1. #include <stdio.h>  
  2. #include <string.h>  
  3.   
  4. int main()  
  5. {  
  6.  char* digits[10] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};  
  7.  char* tens[10] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};  
  8.  char* hundreds[10] = {"", "C"};  
  9.   
  10.  int n, i, j;  
  11.   
  12.  while (scanf("%d", &n) != EOF)  
  13.  {  
  14.   if (n < 1 || n > 100)  
  15.   {  
  16.    printf("please input between 1~100\n");  
  17.    continue;  
  18.   }  
  19.   printf("%s", hundreds[n%1000/100]);  
  20.   printf("%s", tens[n%100/10]);  
  21.   printf("%s\n", digits[n%10]);  
  22.  }  
  23.  system("PAUSE");  
  24.  return 0;  
  25. }  

成績評等


成績評等

成績: 0 / 倒扣: 0.8

請輸入一個0到100的分數,區分為優等(90-100)、甲等(80-89)、乙等(70-79)、丙等(60-69)、丁等(0-59),若輸入不在0-100的區間,則顯示error!!
輸入值可能是浮點數。
例如:

Input

100

Output

優等

Input

50

Output

丁等


  1. int main(int argc, char *argv[])    
  2. {    
  3.     double a;     
  4.     scanf("%lf",&a);    
  5.     
  6.     if ((a>=90)&&(a<=100)){    
  7.        printf("優等\n");    
  8.        }    
  9.     else if((a>=80)&&(a<=89)){    
  10.        printf("甲等\n");    
  11.          }    
  12.     else if((a>=70)&&(a<=79)){    
  13.        printf("乙等\n");    
  14.          }    
  15.     else if((a>=60)&&(a<=69)){    
  16.        printf("丙等\n");    
  17.          }             
  18.     else if((a>=0)&&(a<60)){    
  19.     printf("丁等\n");    
  20.          }    
  21.   else {    
  22.        printf("error!!\n");    
  23.        }    
  24.     
  25.   system("PAUSE");      
  26.   return 0;    
  27. }  

輸入五個數字,分別計算出平均數、變異數、標準差,並精確到小數點後第二位。

平均數參考公式
μ=Σ(Xi)/N
變異數參考公式
Σ(Xi-μ)^2/N
標準差參考公式
(Σ(Xi-μ)^2/N)^(0.5)


例如:1 2 8 9 10
平均值:6.00  (1+2+8+9+10)/5=6
變異數:14.00 Σ(Xi-μ)^2=(1-6)^2+(2-6)^2+(8-6)^2+(9-6)^2+(10-6)^2
                        =25+16+4+9+16=70 70/5=14
標準差14^(0.5)

  1. #include <stdio.h>  
  2. #include <stdlib.h>  
  3. #include <math.h>  
  4. int main(int argc, char *argv[])  
  5. {  
  6.   double a,b,c,d,e,ave,x,y;   
  7. //  pow(10,2);  
  8.   scanf("%lf %lf %lf %lf %lf",&a,&b,&c,&d,&e);  
  9.     ave = (a + b + c + d + e)/5;  
  10.     x = ((pow((a-ave),2))+(pow(b-ave,2))+(pow(c-ave,2))+(pow(d-ave,2))+(pow(e-ave,2)))/5;  
  11.     y = (pow(x,(0.5)));  
  12.   printf("平均值:%.2f\n",ave);  
  13.   printf("變異數:%.2f\n",x);  
  14.   printf("標準差:%.2f\n",y);  
  15.   system("PAUSE");    
  16.   return 0;  
  17. }  

2.3 輸入一個24制時間轉換成12制時間,並加上AM/PM。
輸入的時間必須符合24進制,否則為error!! 

例如:

Input
23:15

Output
11:15 PM

Input
16:61

Output
error!!

Input
03:18  

Output
03:18 AM

  1. #include <stdio.h>  
  2. #include <stdlib.h>  
  3.   
  4. int main(int argc, char *argv[])  
  5. {  
  6.  int a,c;  
  7.   
  8.  scanf("%d:%d",&a,&c);  
  9.  if((a>=0)&&(a<25)&&(c<61)&&(c>=0))  
  10.   {  
  11.    if(a>12)  
  12.     printf("%d:%d PM\n",a-12,c);  
  13.    else  
  14.     printf("%d:%d AM\n",a,c);  
  15.   }  
  16.    else printf("error!!\n");  
  17.           
  18.   system("PAUSE");    
  19.   return 0;  
  20. }  

計算成績

某一學生修國文、計算機概論、計算機程式設計三科,
使用者輸入名字(一個char)、學號(integer)、三科成績(double)。
(1) 計算學生總成績、平均。
(2) 印出名字、學號、總成績、平均。

Input

K
905067
100
100
100

Output

Name: K
Id: 905067
Total: 300
Average: 100



  1. #include <stdio.h>    
  2. #include <stdlib.h>    
  3. #include <math.h>   
  4. int main()    
  5. {    
  6.   char name;     
  7.   int id,total,average;    
  8.   double  chinese, compscience, programming,avg,to,avgint;     
  9.   scanf("%c ",&name);      
  10.   scanf("%d",&id);    
  11.   scanf("%lf",&chinese);    
  12.  scanf("%lf",&compscience);    
  13.   scanf("%lf", &programming);    
  14.   to = (programming + chinese + compscience);  
  15.   total=to;    
  16.   to=to/3;  
  17.   avgint=floor(to);  
  18.   if(to-avgint>0.5) avg=ceil(to);    
  19.   else avg=to;  
  20.   average=avg;  
  21.            printf("Name:%c\n", name);    
  22.            printf("Id:%d\n", id);    
  23.            printf("Total:%d\n", total);    
  24.            printf("Average:%d\n", average);    
  25.   system("PAUSE");      
  26.   return average;    
  27. }  

Binary Conversion

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