由键盘输入正整数n
班級 座號 姓名 1. 由鍵盤輸入正整數n,求n的所有因數(包含n本身)和因數3. 寫一程式,顯示如右 1*1= 1 2*1= 2 3*1= 3
1*2= 2 2*2= 4 3*2= 6 總和(若 n等於其所有因數總和) 10% 結果 10% #include #include 請按任意鍵繼續 . . . 輸入正整數: 24 #include #include 24的因數有 1 2 3 4 6 8 12 24 int main(void) int main(void) 因數和=60 { {
請按任意鍵繼續 . . .
system("pause");
return 0;
} system("pause");
return 0; 4. 寫一程式,印出1~20中, 1 5 7 11 13 17 19 } 所有不被2或3整除的數字,請按任意鍵繼續 . . .
顯示如右結果 10% 2. 試撰寫一非遞迴函數 int cube(int x,int y),可 #include 以傳回x 的 y 次方。 10% #include #include int main(void) #include {
int main(void) {
int x,y; do
{
printf("Input two integer:"); scanf(“%d %d”,&x ,&y);
} while (x<=0||y<=0); printf(“cube(%d,%d)=%d\n”, );
system("pause");
return 0; }
system("pause");
return 0;
} 2 5. 試定義巨集函數f(x)=2x+1,並印出f(5)的值。10%
#include
#include
int main(void) { system("pause"); return 0; }
班級 座號 姓名
#include 6. 定義f(n)=1*2+2*3+3*4+…+(n-1)*n, #include 寫出 f(n)的遞迴式 (n>=1) 5% int main(void)
{
f(n)=
由上的遞迴式,寫出f(n)求的程式 10%
#include Input the number n: 4 #include Answer=20 int main(void) 請按任意鍵繼續 . . . { system("pause"); return 0; }
8. 使用 switch寫一程式,由 輸入運算式: 10+20 鍵盤輸入一運算式x+y或
system("pause"); 10+20=30 x-y或x*y或x/y,並印出運 return 0; 算結果,顯示如右結果 10% 請按任意鍵繼續 . . . }
#include int f(int n)
#include {
int main(void)
{
}
7. 分別用for、while各寫一程式,由鍵盤輸入整數值n(須考
5-22 慮n是大於等於0或小於0,例如2=32、2=1/2=0.25), n寫一程式求 2 。 20%
#include
#include
int main(void)
{
system("pause");
return 0;
}
9. Ackerman’s function A(m,n)的遞迴式定義如下: 5% n,1,ifm,0, , Ack(m-1,1)Ack(m,n)= ,ifn,0, ,,otherwiseAck(m-1,Ack(m,n-1)),
求 ack(1,2)=
system("pause");
return 0;
}