2016年下半年計算機C語言考試題庫及答案
1.下列給定程序中,函數fun的功能是計算如下公式 直到 ,並且把計算結果作為函數值返回。
例如,若形參e的值為1e-3,則函數返回值為0.551690。請在下劃線處填入正確的內容並將下劃線刪除,使程序得出正確的結果。
注意:部分源程序在文件BLANK1.C中。
不得增行或刪行,也不得更改程序的結構!
#include
double fun(double e)
{ int i, k; double s, t, x;
s=0; k=1; i=2;
/**********found**********/
x=__1__/4;
/**********found**********/
while(x __2__ e)
{ s=s+k*x;
k=k* (-1);
t=2*i;
/**********found**********/
x=__3__/(t*t);
i++;
}
return s;
}
main()
{ double e=1e-3;
printf("nThe result is: %fn",fun(e));
}
【參考答案】
(1)3.0或(double)3 (2)> (3) (t+1)
2. 下列給定程序中,函數fun的功能是:計算如下公式前n項的和並作為函數值返回。
例如,當形參n的值為10時,函數返回值為9.612558。
請在下劃線處填入正確的內容並將下劃線刪除,使程序得出正確的結果。
注意:部分源程序在文件BLANK1.C中。
不得增行或刪行,也不得更改程序的結構!
#include
double fun(int n)
{ int i; double s, t;
/**********found**********/
s=__1__;
/**********found**********/
for(i=1; i<=__2__; i++)
{ t=2.0*i;
/**********found**********/
s=s+(2.0*i-1)*(2.0*i+1)/__3__;
}
return s;
}
main()
{ int n=-1;
while(n<0)
{ printf("Please input(n>0): "); scanf("%d",&n); }
printf("nThe result is: %fn",fun(n));
}
【參考答案】
(1) 0 (2) n (3) (t*t)
3.給定程序中,函數fun的功能是:統計形參s所指的字符串中數字字符出現的次數,並存放在形參t所指的變量中,最後在主函數中輸出。例如,若形參s所指的字符串為abcdef35adgh3kjsdf7,則輸出結果為4。
請在下劃線處填入正確內容並將下劃線刪除,使程序得出正確的結果。....
注意:部分源程序在文件BLANK1.C中。
不得增行或刪行,也不得更改程序的結構!
#include
void fun(char *s, int *t)
{ int i, n;
n=0;
/**********found**********/
for(i=0; ___1___ !=0; i++)
/**********found**********/
if(s[i]>='0'&&s[i]<= ___2___ ) n++;
/**********found**********/
___3___ ;
}
main()
{ char s[80]="abcdef35adgh3kjsdf7";
int t;
printf("nThe original string is : %sn",s);
fun(s,&t);
printf("nThe result is : %dn",t);
}
【參考答案】
(1) s[i] (2) '9' (3)*t=n
4.下列給定程序中,函數fun的功能是:把形參a所指數組中的奇數按原順序依次存放到a[0]、a[1]、a[2]、……中,把偶數從數組中刪除,奇數個數通過函數值返回。
例如:若a所指數組中的數據最初排列為:9、1、4、2、3、6、5、8、7,刪除偶數後a所指數組中的數據為:9、1、3、5、7,返回值為5。
請在下劃線處填入正確的內容並將下劃線刪除,使程序得出正確的結果。
注意:部分源程序在文件BLANK1.C中。
不得增行或刪行,也不得更改程序的結構!
#include
#define N 9
int fun(int a[], int n)
{ int i,j;
j = 0;
for (i=0; i
/**********found**********/
if (a[i]%2==___1___)
{
/**********found**********/
a[j] = a[i]; ___2___;
}
/**********found**********/
return ___3___;
}
main()
{ int b[N]={9,1,4,2,3,6,5,8,7}, i, n;
printf("nThe original data :n");
for (i=0; i
printf("n");
n = fun(b, N);
printf("nThe number of odd : %d n", n);
printf("nThe odd number :n");
for (i=0; i
printf("n");
}
【參考答案】
(1)1 (2) j++ (3)j
5.下列給定程序中,函數fun的功能是:將形參n中,各位上為偶數的數取出,並按原來從高位到低位相反的順序組成一個新數,作為函數值返回。
例如,輸入一個整數27638496,函數返回值為64862。
請在下劃線處填入正確的內容並將下劃線刪除,使程序得出正確的結果。
注意:部分源程序在文件BLANK1.C中。
不得增行或刪行,也不得更改程序的結構!
#include
unsigned long fun(unsigned long n)
{ unsigned long x=0; int t;
while(n)
{ t=n%10;
/**********found**********/
if(t%2==____1____)
/**********found**********/
x=____2____+t;
/**********found**********/
n=____3____;
}
return x;
}
main()
{ unsigned long n=-1;
while(n>99999999||n<0)
{ printf("Please input(0
printf("nThe result is: %ldn",fun(n));
}
【參考答案】
(1)0 (2) 10*x (3)n/10
6.下列給定程序中,函數fun的功能是:把形參a所指數組中的最小值放在元素a[0]中,接着把a所指數組中的最大值放在a[1]元素中;再把a所指數組元素中的次小值放在a[2]中,把a所指數組元素中的次大值放在a[3],以此類推。
例如,若a所指數組中的數據最初排列為:9、1、4、2、3、6、5、8、7;則按規則移動後,數據排列為:1、9、2、8、3、7、4、6、5。形參n中存放a所指數組中數據的個數。
規定fun函數中的max存放當前所找的最大值,px存放當前所找最大值的下標。
請在下劃線處填入正確的'內容並將下劃線刪除,使程序得出正確的結果。
注意:部分源程序在文件BLANK1.C中。
不得增行或刪行,也不行更改程序的結構!
# include
#define N 9
void fun(int a[], int n)
{ int i,j, max, min, px, pn, t;
for (i=0; i
{
/**********found**********/
max = min = ___1___;
px = pn = i;
for (j=i+1; j
/**********found**********/
if (max<___2___)
{ max = a[j]; px = j; }
/**********found**********/
if (min>___3___)
{ min = a[j]; pn = j; }
}
if (pn != i)
{ t = a[i]; a[i] = min; a[pn] = t;
if (px == i) px =pn;
}
if (px != i+1)
{ t = a[i+1]; a[i+1] = max; a[px] = t; }
}
}
main()
{ int b[N]={9,1,4,2,3,6,5,8,7}, i;
printf("nThe original data :n");
for (i=0; i
printf("n");
fun(b, N);
printf("nThe data after moving :n");
for (i=0; i
printf("n");
}
【參考答案】
(1) a[i] (2) a[j] (3) a[j]
7.下列給定程序中,函數fun的功能是進行數字字符轉換。若形參ch中是數字字符'0'~'9',則將'0'轉換成'9','1'轉換成'8','2'轉換成'7',……,'9'轉換成'0';若是其它字符則保持不變;並將轉換後的結果作為函數值返回。
請在下劃線處填入正確的內容並將下劃線刪除,使程序得出正確的結果。
注意:部分源程序在文件BLANK1.C中。
不得增行或刪行,也不得更改程序的結構!
#include
/**********found**********/
___1___ fun(char ch)
{
/**********found**********/
if (ch>='0' && ___2___)
/**********found**********/
return '9'- (ch-___3___);
return ch ;
}
main()
{ char c1, c2;
printf("nThe result :n");
c1='2'; c2 = fun(c1);
printf("c1=%c c2=%cn", c1, c2);
c1='8'; c2 = fun(c1);
printf("c1=%c c2=%cn", c1, c2);
c1='a'; c2 = fun(c1);
printf("c1=%c c2=%cn", c1, c2);
}
【參考答案】
(1) char (2) ch<='9' (3)'0'
8.下列給定程序中,函數fun的功能是:求ss所指字符串數組中長度最短的字符串所在的行下標,作為函數值返回,並把其串長放在形參n所指的變量中。ss所指字符串數組中共有M個字符串,且串長
請在下劃線處填入正確的內容並將下劃線刪除,使程序得出正確的結果。
注意:部分源程序在文件BLANK1.C中。
不得增行或刪行,也不得更改程序的結構!
#include
#include
#define M 5
#define N 20
int fun(char (*ss)[N], int *n)
{ int i, k=0, len= N;
/**********found**********/
for(i=0; i<___1___; i++)
{ len=strlen(ss[i]);
if(i==0) *n=len;
/**********found**********/
if(len ___2___ *n)
{ *n=len;
k=i;
}
}
/**********found**********/
return(___3___);
}
main()
{ char ss[M][N]={"shanghai","guangzhou","beijing","tianjing","chongqing"};
int n,k,i;
printf("nThe original strings are :n");
for(i=0;i
k=fun(ss,&n);
printf("nThe length of shortest string is : %dn",n);
printf("nThe shortest string is : %sn",ss[k]);
}
【參考答案】
(1) M (2) < (3) k
更多計算機二級相關試題推薦:
3.2016下半年計算機二級C語言考試試題及答案
4.計算機二級C語言新增無紙化真題試卷
5.2016年9月計算機二級C語言選擇題及答案
6.2016下半年計算機二級C語言預測試題及答案
7.計算機二級C語言試題及答案2016
8.計算機二級C語言考試上機衝刺試題及答案
9.計算機二級c語言題庫2016
10.9月計算機二級c語言試題及答案