2016年計算機二級考試C語(yǔ)言試題及答案
計算機等級考試正在報名,為幫助同學(xué)們在C語(yǔ)言考試中取得好成績(jì),yjbys為大家分享最新C語(yǔ)言考試試題及答案,趕緊來(lái)看看吧!
程序改錯
1
/*--------------------------------------------------------
【程序改錯】
--------------------------------------------------------
功能:依次取出字符串中所有數字字符, 形成新的字符串, 并取代原字符串。
例如:輸入ab12c3d,則輸出123。
注意:不得增行或刪行,也不得更改程序的結構!
------------------------------------------------------*/
#include "stdio.h"
/**********ERROR**********/
void fun(char s)
{
int i,j;
for(i=0,j=0; s[i]!='\0'; i++)
if(s[i]>='0'&&s[i]<='9')
/**********ERROR**********/
s[j]=s[i];
/**********ERROR**********/
s[j]="\0";
}
main()
{
char item[80];
printf("\nEnter a string: ");
gets(item);
printf("\n\nThe string is: \"%s\"\n",item);
fun(item);
printf("\n\nThe string of changing is: \"%s\"\n",item);
}
【改錯1】
【參考答案】
void fun(char *s)
void fun(char s[])
void fun(char s[80])
============================================================
【改錯2】
【參考答案】
s[j++]=s[i];
{ s[j]=s[i]; j++; }
============================================================
【改錯3】
【參考答案】
s[j]='\0';
2
/*------------------------------------------------------
【程序改錯】
--------------------------------------------------------
功能:讀入一個(gè)整數m( 5≤m≤20 ),函數rnd獲得m個(gè)隨機整數,
函數sortpb將這m個(gè)隨機整數從小到大排序。
例如:若輸入整數7,則應輸出:3 10 17 28 32 36 47。
------------------------------------------------------*/
#include "conio.h"
#include "stdio.h"
sortpb ( int n, int a[] )
{
/**********ERROR**********/
int i, j, p;
for ( j = 0; j < n-1 ; j++ )
{
p = j;
for ( i = j + 1; i < n ; i ++ )
/**********ERROR**********/
if ( a[p] > a[j] ) p = i;
/**********ERROR**********/
if ( p == j )
{
t = a[j];
a[j] = a[p];
a[p] = t;
}
}
}
double rnd ( )
{
static t = 29, c = 217, m = 1024, r = 0;
r =( r*t + c )%m; return( ( double )r/m );
}
getarr( int n, int *x )
{
int i;
for( i = 1; i <= n; i++, x++ ) *x = ( int )( 50*rnd() );
}
putarr( int n, int *z )
{
int i;
for( i = 1; i <= n; i++, z++ )
{
printf( "M", *z );
if ( !( i ) ) printf( "\n" );
}
printf("\n");
}
main()
{
int aa[20], n;
printf( "\nPlease enter an integer number between 5 and 20: " );
scanf( "%d", &n );
getarr( n, aa );
printf( "\n\nBefore sorting %d numbers:\n", n ); putarr( n, aa );
sortpb( n, aa );
printf( "\nAfter sorting %d numbers:\n", n ); putarr( n, aa );
}
【改錯1】
【參考答案】
int i, j, p, t;
============================================================
【改錯2】
【參考答案】
if ( a[p] > a[i] ) p = i;
if ( a[i] < a[p] ) p = i;
============================================================
【改錯3】
【參考答案】
if ( p != j )
【計算機二級考試C語(yǔ)言試題及答案】相關(guān)文章:
計算機二級C語(yǔ)言考試試題及答案10-09
計算機等級考試二級C語(yǔ)言考試試題(帶答案)10-30
計算機二級C語(yǔ)言模擬試題及答案08-25
計算機二級C語(yǔ)言沖刺試題及答案10-29
計算機二級考試C++試題及答案08-01
計算機二級考試C++試題及答案10-08