當前位置:才華齋>計算機>計算機四級>

2016年計算機四級機試試題及答案

計算機四級 閱讀(2.59W)

 1./* 請編寫一個函式changestr(char *s),函式的功能是把s串中所有的字元前移一個位置,串中的第一個字元移到最後。

2016年計算機四級機試試題及答案

  例如:s串中原有的字串為:Mn.123xyZ,則呼叫該函式後,s串中的內容為:n.123xyZM。函式ReadWrite()實現從檔案中讀取兩個字串,並呼叫函式 changeStr(),最後把結果輸出到檔案中。

注意:部分源程式存放在檔案PROG1.C中。

請勿改動主函式main()和其它函式中的任何內容,僅在函式changeStr()的花括號中填入你編寫的若干語句。*/

#include

int cnt, sum ;

void countValue()

{

}

void main()

{

cnt = sum = 0 ;

countValue() ;

printf("素數的個數=%dn", cnt) ;

printf("滿足條件素數值的和=%d", sum) ;

writeDAT() ;

}

writeDAT()

{

FILE *fp ;

fp = fopen("", "w") ;

fprintf(fp, "%dn%dn", cnt, sum) ;

fclose(fp) ;

}

  2./* 請編制函式CalValue(),其功能要求是:1.求出這個檔案中共有多少個正整數totNum;2.求這些數中的十位數位置上的`數字2、4和8的數的個數totCnt;以及不滿足此條件的所有數的平均值totPjz,最後呼叫函式WriteDAT()把所求的結果輸出到檔案中。

注意:部分源程式存放在PROG1.C中。

請勿改動主函式main(),讀資料函式ReadDAT()和輸出資料函式

WriteDAT()的內容。*/

#include

#include

#define MAXNUM 200

int xx[MAXNUM] ;

int totNum = 0 ; /* 檔案中共有多少個正整數 */

int totCnt = 0 ; /* 符合條件的正整數的個數 */

double totPjz = 0.0 ; /* 平均值 */

int ReadDat(void) ;

void WriteDat(void) ;

void CalValue(void)

{

}

void main()

{

clrscr() ;

if(ReadDat()) {

printf("資料檔案不能開啟!