課程代碼:00342
二、填充題(每空5分,共30分)
1.階乘n!定義如下:
n!=
函數(shù) fact 計算階乘n!。請在空格上填上適當(dāng)內(nèi)容。
fact (value)
int value;
{
if (value<0)
{
printf (“\n Argument Error ! \n”);
return (-1);
}
else if (value= = (1)___________|| value= =0) return (1);
else return ( (2)___________* fact (value-1));
}
2.下面的程序輸出:
There are two duck on the tree. five duck on the stream.
在程序中填上正確語句至空格,使之能正確運(yùn)行。
# include
# define DUCK “five duck”
main ()
{
char *str1= “There are two duck on the tree.”;
char *str2= “There is a chicken on the stream.”;
char str3 [80];
strcpy (str3, str1);
strcat (str3, DUCK);
strcat (str3, str2+ (3)___________);
prinft (“str3=%s”, (4)___________);
}
3.設(shè)有一函數(shù),其代碼如下:
int power (x,n)
int x,n;
{
int i,p;
for (p=1,i=1; i<=n;++i )
p=p*x;
return(p);
}
現(xiàn)要求取消變量i,重寫該函數(shù)如下,請在空白上填上適當(dāng)內(nèi)容。
power (x,n)
int x,n;
{
int p;
for ( (5)___________; n>0; (6)____________)
p=p*x;
return (p);
二、填充題(每空5分,共30分)
1.階乘n!定義如下:
n!=
函數(shù) fact 計算階乘n!。請在空格上填上適當(dāng)內(nèi)容。
fact (value)
int value;
{
if (value<0)
{
printf (“\n Argument Error ! \n”);
return (-1);
}
else if (value= = (1)___________|| value= =0) return (1);
else return ( (2)___________* fact (value-1));
}
2.下面的程序輸出:
There are two duck on the tree. five duck on the stream.
在程序中填上正確語句至空格,使之能正確運(yùn)行。
# include
# define DUCK “five duck”
main ()
{
char *str1= “There are two duck on the tree.”;
char *str2= “There is a chicken on the stream.”;
char str3 [80];
strcpy (str3, str1);
strcat (str3, DUCK);
strcat (str3, str2+ (3)___________);
prinft (“str3=%s”, (4)___________);
}
3.設(shè)有一函數(shù),其代碼如下:
int power (x,n)
int x,n;
{
int i,p;
for (p=1,i=1; i<=n;++i )
p=p*x;
return(p);
}
現(xiàn)要求取消變量i,重寫該函數(shù)如下,請在空白上填上適當(dāng)內(nèi)容。
power (x,n)
int x,n;
{
int p;
for ( (5)___________; n>0; (6)____________)
p=p*x;
return (p);

