輸入說明: 輸入一個整數 輸出說明: 輸出奇數或偶數
- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc, char *argv[])
- {
- int a;
- scanf("%d",&a);
- if(a%2==0){
- printf("even\n");
- }
- else
- printf("odd\n");
- system("PAUSE");
- return 0;
- }
輸入說明: 輸入一個整數 輸出說明: 輸出奇數或偶數
- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc, char *argv[])
- {
- int a;
- scanf("%d",&a);
- if(a%2==0){
- printf("even\n");
- }
- else
- printf("odd\n");
- system("PAUSE");
- return 0;
- }
已知男生標準體重=(身高-80 )*0.7;女生標準體重=(身高-70)*0.6; 試寫一個程式可以計算男生女生的標準體重。 並精確到小數點第二位 輸入說明: 輸入兩個數值,依序代表為身高及性別(1代表男性;2代表女性)。 輸出說明: 輸出標準體重。
- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc, char *argv[])
- {
- int sex,tall;
- double result;
- scanf("%d",&tall);
- scanf("%d",&sex);
- switch(sex){
- case 1:
- result = (tall-80)*0.7;
- printf("%.2f\n",result);
- break;
- case 2:
- result = (tall-70)*0.6;
- printf("%.2f\n",result);
- break;
- default:
- printf("error\n");
- break;
- }
- system("PAUSE");
- return 0;
- }
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
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- char* digits[10] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
- char* tens[10] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
- char* hundreds[10] = {"", "C"};
- int n, i, j;
- while (scanf("%d", &n) != EOF)
- {
- if (n < 1 || n > 100)
- {
- printf("please input between 1~100\n");
- continue;
- }
- printf("%s", hundreds[n%1000/100]);
- printf("%s", tens[n%100/10]);
- printf("%s\n", digits[n%10]);
- }
- system("PAUSE");
- return 0;
- }
輸入五個數字,分別計算出平均數、變異數、標準差,並精確到小數點後第二位。
平均數參考公式
μ=Σ(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)
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int main(int argc, char *argv[])
- {
- double a,b,c,d,e,ave,x,y;
- // pow(10,2);
- scanf("%lf %lf %lf %lf %lf",&a,&b,&c,&d,&e);
- ave = (a + b + c + d + e)/5;
- x = ((pow((a-ave),2))+(pow(b-ave,2))+(pow(c-ave,2))+(pow(d-ave,2))+(pow(e-ave,2)))/5;
- y = (pow(x,(0.5)));
- printf("平均值:%.2f\n",ave);
- printf("變異數:%.2f\n",x);
- printf("標準差:%.2f\n",y);
- system("PAUSE");
- return 0;
- }
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
- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc, char *argv[])
- {
- int a,c;
- scanf("%d:%d",&a,&c);
- if((a>=0)&&(a<25)&&(c<61)&&(c>=0))
- {
- if(a>12)
- printf("%d:%d PM\n",a-12,c);
- else
- printf("%d:%d AM\n",a,c);
- }
- else printf("error!!\n");
- system("PAUSE");
- return 0;
- }
某一學生修國文、計算機概論、計算機程式設計三科, 使用者輸入名字(一個char)、學號(integer)、三科成績(double)。 (1) 計算學生總成績、平均。 (2) 印出名字、學號、總成績、平均。 Input K 905067 100 100 100 Output Name: K Id: 905067 Total: 300 Average: 100
Problem Description Convert two binary numbers into two decimal numbers and compute their sum. Your program has to convert two binary number...