生活随笔
收集整理的這篇文章主要介紹了
全国计算机等级考试题库二级C操作题100套(第98套)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
第98套:
給定程序中,函數(shù)fun的功能是:在帶有頭結(jié)點的單向鏈表中,查找數(shù)據(jù)域中值為ch的結(jié)點。找到后通過函數(shù)值返回該結(jié)點在鏈表中所處的順序號;若不存在 值為ch的結(jié)點,函數(shù)返回0值。 請在程序的下劃線處填入正確的內(nèi)容并把下劃線刪除,使程序得出正確的結(jié)果。 注意:源程序存放在考生文件夾下的BLANK1.C中。 不得增行或刪行,也不得更改程序的結(jié)構(gòu)! 給定源程序:
#include <stdio.h>
#include <stdlib.h>
#define N 8
typedef struct list
{ int data
;
struct list
* next
;
} SLIST
;
SLIST
* creatlist ( char * ) ;
void outlist ( SLIST
* ) ;
int fun ( SLIST
* h
, char ch
)
{ SLIST
* p
; int n
= 0 ;
p
= h
-> next
;
while ( p
!= ___1___
)
{ n
++ ;
if ( p
-> data
== ch
) return ___2___
;
else p
= p
-> next
;
}
return 0 ;
}
main ( )
{ SLIST
* head
; int k
; char ch
;
char a
[ N
] = { 'm' , 'p' , 'g' , 'a' , 'w' , 'x' , 'r' , 'd' } ;
head
= creatlist ( a
) ;
outlist ( head
) ;
printf ( "Enter a letter:" ) ;
scanf ( "%c" , & ch
) ;
k
= fun ( ___3___
) ;
if ( k
== 0 ) printf ( "\nNot found!\n" ) ;
else printf ( "The sequence number is : %d\n" , k
) ;
}
SLIST
* creatlist ( char * a
)
{ SLIST
* h
, * p
, * q
; int i
;
h
= p
= ( SLIST
* ) malloc ( sizeof ( SLIST
) ) ;
for ( i
= 0 ; i
< N
; i
++ )
{ q
= ( SLIST
* ) malloc ( sizeof ( SLIST
) ) ;
q
-> data
= a
[ i
] ; p
-> next
= q
; p
= q
;
}
p
-> next
= 0 ;
return h
;
}
void outlist ( SLIST
* h
)
{ SLIST
* p
;
p
= h
-> next
;
if ( p
== NULL ) printf ( "\nThe list is NULL!\n" ) ;
else
{ printf ( "\nHead" ) ;
do
{ printf ( "->%c" , p
-> data
) ; p
= p
-> next
; }
while ( p
!= NULL ) ;
printf ( "->End\n" ) ;
}
}
解題思路: 本題是在給定的鏈表中要求找出指定的值。 第一處:判斷p是否結(jié)束,所以應(yīng)填:NULL。 第二處:在函數(shù)fun中,使用n來計算結(jié)點的位置,當(dāng)找到ch值,則返回結(jié)點的位置n,所以應(yīng)填:return n。 第三處:函數(shù)調(diào)用,在主函數(shù)中已經(jīng)給出了head和ch,所以應(yīng)填:head,ch。
給定程序MODI1.C中函數(shù)fun的功能是:刪除p所指字符串中的所有空白字符(包括制表符、回車符及換行符)。 輸入字符串時用’#'結(jié)束輸入。 請改正程序中的錯誤,使它能輸出正確的結(jié)果。 注意:不要改動main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)! 給定源程序:
#include <string.h>
#include <stdio.h>
#include <ctype.h>
fun
( char * p
)
{ int i
, t
; char c
[ 80 ] ;
For
( i
= 0 , t
= 0 ; p
[ i
] ; i
++ )
if ( ! isspace ( * ( p
+ i
) ) ) c
[ t
++ ] = p
[ i
] ; c
[ t
] = "\0" ;
strcpy ( p
, c
) ;
}
main ( )
{ char c
, s
[ 80 ] ;
int i
= 0 ;
printf ( "Input a string:" ) ;
c
= getchar ( ) ;
while ( c
!= '#' )
{ s
[ i
] = c
; i
++ ; c
= getchar ( ) ; }
s
[ i
] = '\0' ;
fun ( s
) ;
puts ( s
) ;
}
解題思路: 第一處:保留字for錯寫成For。 第二處:置字符串結(jié)束符錯誤,應(yīng)該是:’\0’。
請編寫一個函數(shù)fun,它的功能是:將ss所指字符串中所有下標(biāo)為奇數(shù)位置上的字母轉(zhuǎn)換為大寫(若該位置上不是字母,則不轉(zhuǎn)換)。 例如, 若輸入"abc4EFg",則應(yīng)輸出"aBc4EFg"。 注意: 部分源程序存在文件PROG1.C中。 請勿改動主函數(shù)main和其它函數(shù)中的任何內(nèi)容,僅在函數(shù)fun的花括號中填入你編寫的若干語句。 給定源程序:
#include <stdio.h>
#include <string.h>
void fun
( char * ss
)
{
}
main ( )
{ char tt
[ 81 ] ;
printf ( "\nPlease enter an string within 80 characters:\n" ) ; gets ( tt
) ;
printf ( "\n\nAfter changing, the string\n \"%s\"" , tt
) ;
fun ( tt
) ;
printf ( "\nbecomes\n \"%s\"\n" , tt
) ;
NONO
( ) ;
}
解題思路: 本題是考察考生對字母按要求進行轉(zhuǎn)換。其中大小字母的ASCII值相差32。 參考答案:
void fun
( char * ss
)
{
int i
;
for ( i
= 1 ; i
< strlen ( * ss
) ; i
+ = 2 ) {
if ( ss
[ i
] >= 'a' && ss
[ i
] <= 'z' ) ss
[ i
] - = 32 ;
}
}
總結(jié)
以上是生活随笔 為你收集整理的全国计算机等级考试题库二级C操作题100套(第98套) 的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔 網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔 推薦給好友。