黄色在线观看视频-黄色在线免费看-黄色在线视频免费-黄色在线视频免费看-免费啪啪网-免费啪啪网站

首頁 考試吧論壇 Exam8視線 考試商城 網絡課程 模擬考試 考友錄 實用文檔 繽紛校園 英語學習
2010考研 | 2010高考 | 2010中考 | 自學考試 | 成人高考 | 專升本 | 法律碩士 | MBA/MPA | 中科院
四六級 | 商務英語 | 公共英語 | 職稱日語 | 職稱英語 | 博思 | 口譯筆譯 | GRE GMAT | 日語 | 托福
雅思 | 專四專八 | 新概念 | 自考英語 | 零起點英韓語 | 在職申碩英語
在職攻碩英語 | 成人英語三級
等級考試 | 水平考試 | 微軟認證 | 思科認證 | Oracle認證 | Linux認證
公務員 | 報關員 | 報檢員 | 外銷員 | 司法考試 | 導游考試 | 教師資格 | 國際商務師 | 跟單員
單證員 | 物流師 | 價格鑒證師 | 銀行從業資格 | 證券從業資格 | 人力資源管理師 | 管理咨詢師
期貨從業資格 | 社會工作者
會計職稱 | 注會CPA | 經濟師 | 統計師 | 注冊稅務師 | 評估師 | 精算師 | 高會 | ACCA | 審計師
法律顧問 | 會計證
一級建造師 | 二級建造師 | 造價師 | 監理師 | 安全師 | 咨詢師 | 結構師 | 建筑師 | 安全評價師
房地產估價師 | 土地估價師 | 設備監理師 | 巖土工程師 | 質量資格 | 房地產經紀人 | 造價員
投資項目管理 | 土地代理人 | 環保師 | 環境影響評價 | 物業管理師 | 城市規劃師 | 公路監理師
公路造價工程師 | 招標師
執業護士 | 執業醫師 | 執業藥師 | 衛生資格

1999年9月全國計算機等級考試四級機試試題及答案(已運行通過)

1./*PROG1 已知在文件IN.DAT中存有若干個(個數<200)四位數字的正整數,
函數ReadDat()是讀取這若干個正整數并存入數組XX中。請編制函數CalValue(),
其功能要求:1、求出這文件中共有多少個正整數totNum;2、求出這些數中的
各位數字之和是偶數的數的個數totCnt,以及滿足此條件的這些數的算術平均
值totpjZ,最后調用函數WriteDat()把所求的結果輸出到文件OUT2.DAT中。
注意:部分部分源程序存放在PROG1.C中。
請勿改動主函數main(),讀數據函數ReacdDat()和輸出數據函數WriteDat()的內容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少個正整數 */
int totCnt = 0 ; /* 符合條件的正整數的個數 */
double totPjz = 0.0 ; /* 平均值 */

int ReadDat(void) ;
void WriteDat(void) ;

void CalValue(void)
{ int i;
int a,b,c,d;
double sum=0;
for (i=0;i<MAXNUM;i++)
if (xx[i]>0)
{
totNum++;
a=xx[i]/1000;
b=xx[i]/100-a*10;
c=xx[i]/10-a*100-b*10;
d=xx[i]%10;
if((a+b+c+d)%2==0)
{totCnt++;
sum=sum+xx[i];
}
}
totPjz=sum/totCnt;
}


void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數=%d個\n", totNum) ;
printf("符合條件的正整數的個數=%d個\n", totCnt) ;
printf("平均值=%.2lf\n", totPjz) ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;

if((fp = fopen("in.dat", "r")) == NULL) return 1 ;
while(!feof(fp)) {
fscanf(fp, "%d,", &xx[i++]) ;

}
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;

fp = fopen("OUT2.DAT", "w") ;
fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
fclose(fp) ;
}

2./*PROG2 已知在文件IN.DAT中存有若干個(個數<200)四位數字的正整數,
函數ReadDat()是讀取這若干個正整數并存入數組XX中。請編制函數CalValue(),
其功能要求:1、求出這文件中共有多少個正整數totNum;2、求出這些數右移
1位后,產生的新數是偶數的數的個數totCnt,以及滿足此條件的這些數(右移
前的值)的算術平均值totpjZ,最后調用函數WriteDat()把所求的結果輸出到
文件OUT4.DAT中。
注意:部分部分源程序存放在PROG2.C中。
請勿改動主函數main(),讀數據函數ReacdDat()和輸出數據函數WriteDat()的內容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少個正整數 */
int totCnt = 0 ; /* 符合條件的正整數的個數 */
double totPjz = 0.0 ; /* 平均值 */

int ReadDat(void) ;
void WriteDat(void) ;

void CalValue(void)
{ int i,s;
double sum=0;
for (i=0;i<MAXNUM;i++)
if (xx[i]>0)
{ totNum++;
s=xx[i];
s=s>>1;
if ((s%2)==0)
{
totCnt++;
sum=sum+xx[i];
}
}
totPjz=sum/totCnt;
}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數=%d個\n", totNum) ;
printf("符合條件的正整數的個數=%d個\n", totCnt) ;
printf("平均值=%.2lf\n", totPjz) ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;

if((fp = fopen("in.dat", "r")) == NULL) return 1 ;
while(!feof(fp)) {
fscanf(fp, "%d,", &xx[i++]) ;
}
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;

fp = fopen("OUT4.DAT", "w") ;
fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
fclose(fp) ;
}

3./*PROG3 已知在文件IN.DAT中存有若干個(個數<200)四位數字的正整數,
函數ReadDat()是讀取這若干個正整數并存入數組XX中。請編制函數CalValue(),
其功能要求:1、求出這文件中共有多少個正整數totNum;2、求出這些數中的
個位數位置上的數字是3.6和9的數的數的個數totCnt,以及滿足此條件的這些
數的算術平均值totpjZ,最后調用函數WriteDat()把所求的結果輸出到文件
OUT5.DAT中。
注意:部分部分源程序存放在PROG3.C中。
請勿改動主函數main(),讀數據函數ReacdDat()和輸出數據函數WriteDat()的內容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少個正整數 */
int totCnt = 0 ; /* 符合條件的正整數的個數 */
double totPjz = 0.0 ; /* 平均值 */

int ReadDat(void) ;
void WriteDat(void) ;

void CalValue(void)
{ int i,gw;
double sum=0;
for(i=0;i<MAXNUM;i++)
if (xx[i]>0)
{ totNum++;
gw=xx[i]%10;
if((gw==3)||(gw==6)||(gw==9))
{
totCnt++;
sum=sum+xx[i];
}
}
totPjz=sum/totCnt;
}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數=%d個\n", totNum) ;
printf("符合條件的正整數的個數=%d個\n", totCnt) ;
printf("平均值=%.2lf\n", totPjz) ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;

if((fp = fopen("in.dat", "r")) == NULL) return 1 ;
while(!feof(fp)) {
fscanf(fp, "%d,", &xx[i++]) ;
}
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;

fp = fopen("OUT5.DAT", "w") ;
fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
fclose(fp) ;
}

4./*PROG4 已知在文件IN.DAT中存有若干個(個數<200)四位數字的正整數,
函數ReadDat()是讀取這若干個正整數并存入數組XX中。請編制函數CalValue(),
其功能要求:1、求出這文件中共有多少個正整數totNum;2、求出這些數中的
千位數位置上的數字大于個位數位置上的數字的數的個數totCnt,以及滿足此
條件的這些數的算術平均值totpjZ,最后調用函數WriteDat()把所求的結果輸
出到文件OUT8.DAT中。
注意:部分部分源程序存放在PROG4.C中。
請勿改動主函數main(),讀數據函數ReacdDat()和輸出數據函數WriteDat()的內容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少個正整數 */
int totCnt = 0 ; /* 符合條件的正整數的個數 */
double totPjz = 0.0 ; /* 平均值 */

int ReadDat(void) ;
void WriteDat(void) ;

void CalValue(void)
{ int i;
int qw,gw;
double sum=0;
for (i=0;i<MAXNUM;i++)
if (xx[i]>0)
{
totNum++;
qw=xx[i]/1000;
gw=xx[i]%10;
if(qw>gw)
{
totCnt++;
sum=sum+xx[i];
}
}
totPjz=sum/totCnt;

}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數=%d個\n", totNum) ;
printf("符合條件的正整數的個數=%d個\n", totCnt) ;
printf("平均值=%.2lf\n", totPjz) ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;

if((fp = fopen("in.dat", "r")) == NULL) return 1 ;
while(!feof(fp)) {
fscanf(fp, "%d,", &xx[i++]) ;
}
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;

fp = fopen("OUT8.DAT", "w") ;
fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
fclose(fp) ;
}

5./*PROG5 已知在文件IN.DAT中存有若干個(個數<200)四位數字的正整數,
函數ReadDat()是讀取這若干個正整數并存入數組XX中。請編制函數CalValue(),
其功能要求:1、求出這文件中共有多少個正整數totNum;2、求出這些數中的
百位數位置上的數字是1、5和7的數的個數totCnt,以及滿足此條件的這些數的
算術平均值totpjZ,最后調用函數WriteDat()把所求的結果輸出到文件OUT7.DAT中。
注意:部分部分源程序存放在PROG5.C中。
請勿改動主函數main(),讀數據函數ReacdDat()和輸出數據函數WriteDat()的內容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少個正整數 */
int totCnt = 0 ; /* 符合條件的正整數的個數 */
double totPjz = 0.0 ; /* 平均值 */

int ReadDat(void) ;
void WriteDat(void) ;

void CalValue(void)
{ int i;
int bw,qw;
double sum=0;
for (i=0;i<MAXNUM;i++)
if(xx[i]>0)
{totNum++;
qw=xx[i]/1000;
bw=xx[i]/100-qw*10;
if((bw==1)||(bw==5)||(bw==7))
{totCnt++;
sum=sum+xx[i];
}
}
totPjz=sum/totCnt;
}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數=%d個\n", totNum) ;
printf("符合條件的正整數的個數=%d個\n", totCnt) ;
printf("平均值=%.2lf\n", totPjz) ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;

if((fp = fopen("in.dat", "r")) == NULL) return 1 ;
while(!feof(fp)) {
fscanf(fp, "%d,", &xx[i++]) ;
}
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;

fp = fopen("OUT7.DAT", "w") ;
fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
fclose(fp) ;
}

6./*PROG6 已知在文件IN.DAT中存有若干個(個數<200)四位數字的正整數,
函數ReadDat()是讀取這若干個正整數并存入數組XX中。請編制函數CalValue(),
其功能要求:1、求出這文件中共有多少個正整數totNum;2、求出這些數右移1
位后,產生的新數是奇數的數的個數totCnt,以及滿足此條件的這些數(右移前
的值)的算術平均值totpjZ,最后調用函數WriteDat()把所求的結果輸出到文件
OUT3.DAT中。
注意:部分部分源程序存放在PROG6.C中。
請勿改動主函數main(),讀數據函數ReacdDat()和輸出數據函數WriteDat()的內容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少個正整數 */
int totCnt = 0 ; /* 符合條件的正整數的個數 */
double totPjz = 0.0 ; /* 平均值 */

int ReadDat(void) ;
void WriteDat(void) ;

void CalValue(void)
{int i,s;
double sum=0;
for (i=0;i<MAXNUM;i++)
if (xx[i]>0)
{
totNum++;
s=xx[i];
s=s>>1;
if((s%2)==0)
{
totCnt++;
sum=sum+xx[i];
}
}
totPjz=sum/totCnt;

}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數=%d個\n", totNum) ;
printf("符合條件的正整數的個數=%d個\n", totCnt) ;
printf("平均值=%.2lf\n", totPjz) ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;

if((fp = fopen("in.dat", "r")) == NULL) return 1 ;
while(!feof(fp)) {
fscanf(fp, "%d,", &xx[i++]) ;
}
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;

fp = fopen("OUT3.DAT", "w") ;
fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
fclose(fp) ;
}

7./*PROG7 已知在文件IN.DAT中存有若干個(個數<200)四位數字的正整數,
函數ReadDat()是讀取這若干個正整數并存入數組XX中。請編制函數CalValue(),
其功能要求:1、求出這文件中共有多少個正整數totNum;2、求出這些數中的
百位數位置上的數字小于十位數位置上的數字的數的個數totCnt,以及滿足此
條件的這些數的算術平均值totpjZ,最后調用函數WriteDat()把所求的結果輸
出到文件OUT9.DAT中。
注意:部分部分源程序存放在PROG7.C中。
請勿改動主函數main(),讀數據函數ReacdDat()和輸出數據函數WriteDat()的內容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少個正整數 */
int totCnt = 0 ; /* 符合條件的正整數的個數 */
double totPjz = 0.0 ; /* 平均值 */

int ReadDat(void) ;
void WriteDat(void) ;

void CalValue(void)
{int qw,bw,sw;
int i;
double sum=0;
for (i=0;i<MAXNUM;i++)
if (xx[i]>0)
{
totNum++;
qw=xx[i]/1000;
bw=xx[i]/100-qw*10;
sw=xx[i]/10-qw*100-bw*10;
if (bw<sw)
{
totCnt++;
sum+=xx[i];
}
}
totPjz=sum/totCnt;
}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數=%d個\n", totNum) ;
printf("符合條件的正整數的個數=%d個\n", totCnt) ;
printf("平均值=%.2lf\n", totPjz) ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;

if((fp = fopen("in.dat", "r")) == NULL) return 1 ;
while(!feof(fp)) {
fscanf(fp, "%d,", &xx[i++]) ;
}
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;

fp = fopen("OUT9.DAT", "w") ;
fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
fclose(fp) ;
}

8./*PROG8 已知在文件IN.DAT中存有若干個(個數<200)四位數字的正整數,
函數ReadDat()是讀取這若干個正整數并存入數組XX中。請編制函數CalValue(),
其功能要求:1、求出這文件中共有多少個正整數totNum;2、求出這些數中的
十位數位置上的數字是2、4和8的數的個數totCnt,以及滿足此條件的這些數的
算術平均值totpjZ,最后調用函數WriteDat()把所求的結果輸出到文件OUT6.DAT中。
注意:部分部分源程序存放在PROG8.C中。
請勿改動主函數main(),讀數據函數ReacdDat()和輸出數據函數WriteDat()的內容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少個正整數 */
int totCnt = 0 ; /* 符合條件的正整數的個數 */
double totPjz = 0.0 ; /* 平均值 */

int ReadDat(void) ;
void WriteDat(void) ;

void CalValue(void)
{ int i,qw,bw,sw;
double sum=0;
for (i=0;i<MAXNUM;i++)
if (xx[i]>0)
{
totNum++;
qw=xx[i]/1000;
bw=xx[i]/100-qw*10;
sw=xx[i]/10-qw*100-bw*10;
if ((sw==2)||(sw==4)||(sw==8))
{
totCnt++;
sum=sum+xx[i];
}
}
totPjz = sum / totCnt;
}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數=%d個\n", totNum) ;
printf("符合條件的正整數的個數=%d個\n", totCnt) ;
printf("平均值=%.2lf\n", totPjz) ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;

if((fp = fopen("in.dat", "r")) == NULL) return 1 ;
while(!feof(fp)) {
fscanf(fp, "%d,", &xx[i++]) ;
}
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;

fp = fopen("OUT6.DAT", "w") ;
fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
fclose(fp) ;
}

9./*PROG9 已知在文件IN.DAT中存有若干個(個數<200)四位數字的正整數,
函數ReadDat()是讀取這若干個正整數并存入數組XX中。請編制函數CalValue(),
其功能要求:1、求出這文件中共有多少個正整數totNum;2、求出這些數中的
千位數位置上的數字與十位數位置上的數字均為奇數的數的個數totCnt,以及
滿足此條件的這些數的算術平均值totpjZ,最后調用函數WriteDat()把所求的
結果輸出到文件OUT10.DAT中。
注意:部分部分源程序存放在PROG9.C中。
請勿改動主函數main(),讀數據函數ReacdDat()和輸出數據函數WriteDat()的內容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少個正整數 */
int totCnt = 0 ; /* 符合條件的正整數的個數 */
double totPjz = 0.0 ; /* 平均值 */

int ReadDat(void) ;
void WriteDat(void) ;

void CalValue(void)
{ int i,qw,bw,sw;
double sum=0;
for (i=0;i<MAXNUM;i++)
if (xx[i]>0)
{
totNum++;
qw=xx[i]/1000;
bw=xx[i]/100-qw*10;
sw=xx[i]/10-qw*100-bw*10;
if (((qw%2)==0) && ((sw%2)==0))
{
totCnt++;
sum=sum+xx[i];
}
}
totPjz = sum / totCnt;
}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數=%d個\n", totNum) ;
printf("符合條件的正整數的個數=%d個\n", totCnt) ;
printf("平均值=%.2lf\n", totPjz) ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;

if((fp = fopen("in.dat", "r")) == NULL) return 1 ;
while(!feof(fp)) {
fscanf(fp, "%d,", &xx[i++]) ;
}
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;

fp = fopen("OUT10.DAT", "w") ;
fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
fclose(fp) ;
}

10./*PROG10 已知在文件IN.DAT中存有若干個(個數<200)四位數字的正整數,
函數ReadDat()是讀取這若干個正整數并存入數組XX中。請編制函數CalValue(),
其功能要求:1、求出這文件中共有多少個正整數totNum;2、求出這些數中的各
位數字之和是奇數的數的個數totCnt,以及滿足此條件的這些數的算術平均值
totpjZ,最后調用函數WriteDat()把所求的結果輸出到文件OUT1.DAT中。
注意:部分部分源程序存放在PROG10.C中。
請勿改動主函數main(),讀數據函數ReacdDat()和輸出數據函數WriteDat()的內容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少個正整數 */
int totCnt = 0 ; /* 符合條件的正整數的個數 */
double totPjz = 0.0 ; /* 平均值 */

int ReadDat(void) ;
void WriteDat(void) ;

void CalValue(void)
{ int i;
int qw,bw,sw,gw;
double sum=0;
for ( i=0 ; i<MAXNUM; i++)
if (xx[i] > 0)
{
totNum ++ ;
qw = xx[i] / 1000;
bw = xx[i] / 100 - qw * 10;
sw = xx[i] / 10 - qw * 100- bw * 10;
gw = xx[i] % 10;
if ( ( (qw+bw+sw+gw) % 2)!=0)
{
totCnt ++ ;
sum = sum + xx[i];
}
}
totPjz = sum / totCnt;

}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數=%d個\n", totNum) ;
printf("符合條件的正整數的個數=%d個\n", totCnt) ;
printf("平均值=%.2lf\n", totPjz) ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;

if((fp = fopen("in.dat", "r")) == NULL) return 1 ;
while(!feof(fp)) {
fscanf(fp, "%d,", &xx[i++]) ;
}
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;

fp = fopen("OUT1.DAT", "w") ;
fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
fclose(fp) ;
}                      

          2000年9月全真試題
1./* 程序PROG1.C的功能是:選出100至1000之間所有個位數字與十位數字之和
被10除所得余數恰是百位數字的素數(如293)。計算并輸出上述這些素數的個
數cnt以及這些素數值的和sum。
請考生編寫函數countValue( )實現程序的要求,最后調用函數writeDAT( )把
結果cnt和sum輸出到文件out6.DAT中。
注意:部分源程序存放在PROG1.C中。
請勿改動主函數main( )和輸出數據函數writeDAT( )的內容。 */
#include <stdio.h>
int cnt, sum ;

void countValue()
{

}

void main()
{
cnt = sum = 0 ;

countValue() ;
printf("素數的個數=%d\n", cnt) ;
printf("滿足條件素數值的和=%d", sum) ;
writeDAT() ;
}

writeDAT()
{
FILE *fp ;

fp = fopen("OUT6.DAT", "w") ;
fprintf(fp, "%d\n%d\n", cnt, sum) ;
fclose(fp) ;
}


2. /* 編寫函數sumValue( ),它的功能是:計算正整數n的所有因子(1和n除外)之
和作為函數值返回。
例如:n=20時,函數值為21。
函數ReadWrite( )是實現從文件in9.dat中讀取兩個字符串,并調用函數
sumValue(),最后把結果輸出到文件out9.dat中。
注意:部分源程序存在文件PROG1.C中,請勿改動主函數main()和其它函數
中的任何內容,僅在函數sumValue()的花括號中填入你編寫的若干語句。 */
#include <conio.h>
#include <stdio.h>
int sumValue(int n)
{

}

main()
{ clrscr() ;
printf("%d\n", sumValue(20)) ;
ReadWrite() ;
}

ReadWrite()
{
FILE *fp, *wf ;
int i, n, s ;

fp = fopen("in9.dat","r") ;
if(fp == NULL) {
printf("數據文件in9.dat不存在!") ;
return ;
}
wf = fopen("out9.dat","w") ;
for(i = 0 ; i < 10 ; i++) {
fscanf(fp, "%d", &n) ;
s = sumValue(n) ;
fprintf(wf, "%d\n", s) ;
}
fclose(fp) ;
fclose(wf) ;
}

3./* 請編寫一個函數changeStr(char *s),函數的功能是把s串中所有的字
母改寫成該字母的下一個字母,字母z改寫成字母a。大寫仍為大寫字母,
小寫字母仍為小寫字母,其它的字符不變。
函數ReadWrite()實現從文件in2.dat中讀取兩個字符串,并調用函
數changestr(),最后把結果輸出到文件out2.dat中。
注意:部分源程序存在文件PROG1.C中。請勿改動主函數main()和其
它函數中的任何內容,僅在函數changeStr()的花括號中填入你編寫的若干語名。*/
#include <conio.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#define N 81
changeStr ( char *s )
{

}

main( )
{
char a[N] ;
clrscr( ) ;
printf ( "Enter a string : " ) ; gets ( a ) ;
printf ( "The original string is : " ) ; puts( a ) ;
changeStr ( a ) ;
printf ( "The string after modified : ") ;
puts ( a ) ;
ReadWrite( ) ;
}

ReadWrite( )
{
int i ;
char a[N] ;
FILE *rf, *wf ;

rf = fopen("in2.dat", "r") ;
wf = fopen("out2.dat", "w") ;
for(i = 0 ; i < 10 ; i++) {
fscanf(rf, "%s", a) ;
changeStr(a) ;
fprintf(wf, "%s\n", a) ;
}
fclose(rf) ;
fclose(wf) ;
}

4./* 程序PROG1.C的功能是:利用以下所示的簡單迭代方法求方程:
cos(x)-x=0的一個實根。
Xn+1=cos(Xn)
迭代步驟如下:
(1) 取x1初步值為0.0;
(2) x0=x1,把x1,把x1的值賦給x0;
(3) x1=cos(x0),求出一個新的x1;
(4) 若x0-x1的絕對值小于0.000001,執行步驟(5),否則執行步驟(2);
(5) 所求x1就是方程cos(x)-x=0的一個實根,作為函數值返回。
請編寫函數countValue()實現程序的要求,最后調用函數writeDAT()把
結果輸出到文件out4.dat中。
注意:部分源程序存在文件PROG1.C中,請勿改動主函數main()和輸出數
據函數WriteDAT()的內容。 */
#include <conio.h>
#include <math.h>
#include <stdio.h>
float countValue()
{

}

main()
{
clrscr();
printf("實根=%f\n", countValue());
printf(" %f\n",cos(countValue())-countValue());
writeDAT();
}

writeDAT()
{
FILE *wf ;

wf=fopen("out4.dat","w") ;
fprintf(wf, "%f\n", countValue()) ;
fclose(wf) ;
}

5./* 已知在文件IN.DAT中存有若干個(個數<200)四位數字的正整數,
函數ReadDAT()讀取這些正整數并存入數組xx中。
請編制函數CalValue()其功能要求是:1.求出這個文件中共有多
少個正整數totNum;2.求出這些數中的各位數字之和是奇數的數的個
數totCnt,以及不滿足此條件的所有數的算術平均值totPjz,最后調
用函數WriteDAT()把所求的結果輸出到文件OUT8.DAT中。
注意:部分源程序存放在PROG1.C中。
請勿改動主函數main(),讀數據函數ReadDAT()和輸出數據函數
WriteDAT()的內容。 */
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少個正整數 */
int totCnt = 0 ; /* 符合條件的正整數的個數 */
double totPjz = 0.0 ; /* 平均值 */

int ReadDat(void) ;
void WriteDat(void) ;

void CalValue(void)
{

}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數=%d個\n", totNum) ;
printf("符合條件的正整數的個數=%d個\n", totCnt) ;
printf("平均值=%.2lf\n", totPjz) ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;

if((fp = fopen("in.dat", "r")) == NULL) return 1 ;
while(!feof(fp)) {
fscanf(fp, "%d,", &xx[i++]) ;
}
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;

fp = fopen("OUT8.DAT", "w") ;
fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
fclose(fp) ;
}

6./* 編寫一個函數findstr(),該函數統計一個長度為2的子字符串在另一個
字符串中出現的次數。例如,假定輸入的字符串為“asd asasdfg asd as
zx67 asd mklo”,子字符串為“as”,則輸出6。
函數ReadWrite()實現從文件in1.dat中讀取兩個字符串,并調用函數
findStr(),最后把結果輸出到文件out1.dat中。
注意:部分源程序存在文件PROG1.C中。請勿改動主函數main()和其它
函數中的任何內容,僅在函數findStr()的花括號中填入你編寫的若干語句。*/
#include <stdio.h>
#include <string.h>
#include <conio.h>

int findStr(char *str,char *substr)
{

}

main()
{
char str[81], substr[3] ;
int n ;

clrscr() ;
gets(str) ;
gets(substr) ;
puts(str) ;
puts(substr) ;
n=findStr(str, substr) ;
printf("n=%d\n", n) ;
ReadWrite() ;
}

ReadWrite()
{
char str[81], substr[3], ch;
int n, len, i = 0;
FILE *rf, *wf ;

rf = fopen("in1.dat", "r") ;
wf = fopen("out1.dat", "w") ;
while(i < 5) {
fgets(str, 80, rf) ;
fgets(substr, 10, rf) ;
len = strlen(substr) - 1 ;
ch = substr[len] ;
if(ch == '\n' || ch == 0x1a) substr[len] = 0 ;
n=findStr(str, substr);
fprintf(wf, "%d\n", n) ;
i++ ;
}
fclose(rf) ;
fclose(wf) ;
}

7./* 請編寫函數Void countValue(int *a,int *n),它的功能是:
求出1到1000之內能被7或11整除但不能同時被7和11整除的所有整數,
并放在數組a中,然后通過n返回這些數的個數。
注意:部分源程序存入在PROG1.C中。
請改動主函數main()和輸入輸出數據函數WriteDAT()的內容。*/
#include <stdio.h>
int cnt, sum ;

void countValue()
{

}

void main()
{
cnt = sum = 0 ;

countValue() ;
printf("素數的個數=%d\n", cnt) ;
printf("滿足條件素數值的和=%d", sum) ;
writeDAT() ;
}

writeDAT()
{
FILE *fp ;

fp = fopen("OUT6.DAT", "w") ;
fprintf(fp, "%d\n%d\n", cnt, sum) ;
fclose(fp) ;
}

8./* 請編寫一個函數changestr(char *s),函數的功能是把s串中所有的字
符前移一個位置,串中的第一個字符移到最后。
例如:s串中原有的字符串為:Mn.123xyZ,則調用該函數后,s串中的
內容為:n.123xyZM。
函數ReadWrite()實現從文件in3.dat中讀取兩個字符串,并調用函數
changeStr(),最后把結果輸出到文件out3.dat中。
注意:部分源程序存放在文件PROG1.C中。
請勿改動主函數main()和其它函數中的任何內容,僅在函數
changeStr()的花括號中填入你編寫的若干語句。*/
#include <stdio.h>
int cnt, sum ;

void countValue()
{

}

void main()
{
cnt = sum = 0 ;

countValue() ;
printf("素數的個數=%d\n", cnt) ;
printf("滿足條件素數值的和=%d", sum) ;
writeDAT() ;
}

writeDAT()
{
FILE *fp ;

fp = fopen("OUT6.DAT", "w") ;
fprintf(fp, "%d\n%d\n", cnt, sum) ;
fclose(fp) ;
}


9./* 請編制函數CalValue(),其功能要求是:1.求出這個文件中共有多
少個正整數totNum;2.求這些數中的十位數位置上的數字2、4和8的數的
個數totCnt;以及不滿足此條件的所有數的平均值totPjz,最后調用函
數WriteDAT()把所求的結果輸出到文件out7.DAT中。
注意:部分源程序存放在PROG1.C中。
請勿改動主函數main(),讀數據函數ReadDAT()和輸出數據函數
WriteDAT()的內容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少個正整數 */
int totCnt = 0 ; /* 符合條件的正整數的個數 */
double totPjz = 0.0 ; /* 平均值 */

int ReadDat(void) ;
void WriteDat(void) ;

void CalValue(void)
{

}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數=%d個\n", totNum) ;
printf("符合條件的正整數的個數=%d個\n", totCnt) ;
printf("平均值=%.2lf\n", totPjz) ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;

if((fp = fopen("in.dat", "r")) == NULL) return 1 ;
while(!feof(fp)) {
fscanf(fp, "%d,", &xx[i++]) ;
}
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;

fp = fopen("OUT7.DAT", "w") ;
fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
fclose(fp) ;
}

10./* 已知在文件IN.BAT中存有N個實數(N<200),函數ReadDAT()讀取
這N個實數并存入數組XX中。
請編制函數CalValue(),其功能要求是:1.求出這N個實數的平
均值aver;2.分別求出這N個實數的整數部分值的平均值averint以
及其小數部分值的平均值averdel,最后調用函數WriteDAT()把所求
的結果輸出到文件out10.DAT中。
注意:部分源程序存放在文件PROG1.C中。
請勿改動主函數main(),讀數據函數ReadDAT()和輸出數據函數
WreitDAT的內容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

float xx[MAXNUM] ;
int N = 0 ; /* 文件IN.DAT中共有多少個實數 */
double aver = 0.0 ; /* 平均值 */
double averint = 0.0 ; /* 整數部分值的平均值 */
double averdec = 0.0 ; /* 小數部分值的平均值 */
int ReadDat(void) ;
void WriteDat(void) ;

void CalValue(void)
{

}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數據文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有實數%d個\n", N) ;
printf("平均值=%.2lf\n", aver) ;
printf("整數部分值的平均值=%.2lf\n", averint) ;
printf("小數部分值的平均值=%.2lf\n", averdec) ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int j ;

if((fp = fopen("in.dat", "r")) == NULL) return 1 ;
while(!feof(fp)) {
fscanf(fp, "%f,", &xx[N]) ;
if(xx[N] > 0.001) N++ ;
}
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;

fp = fopen("OUT10.DAT", "w") ;
fprintf(fp, "%d\n%.2lf\n%.2lf\n%.2lf\n", N, aver, averint, averdec) ;
fclose(fp) ;
}    

文章搜索
版權聲明:如果計算機等級考試網所轉載內容不慎侵犯了您的權益,請與我們聯系800@exam8.com,我們將會及時處理。如轉載本計算機等級考試網內容,請注明出處。
主站蜘蛛池模板: 久久激情综合色丁香 | 性8sex亚洲区入口 | 欧美奶水| 亚洲综合激情在线影院 | 91av短视频| 日韩中文字幕网站 | 国产伦一区二区三区免费 | 人人成人免费公开视频 | 久久久2019精品 | 日本人成年视频在线观看 | 伦理剧在线播放 | 性欧美暴力猛交xxxxx高清 | 欧美羞羞视频 | 欧美大交乱xxxx | 天天操夜夜操美女 | 国产精品一区二区久久精品 | 日本视频a| 亚洲毛片在线播放 | a级片免费观看视频 | 乱色美www女麻豆 | 一级毛片视频 | a在线免费观看视频 | 日本三级在线观看免费 | www.夜夜爽| 日本三级香港三级人妇99 | 欧美乱子伦一区二区三区 | 久青草香蕉精品视频在线 | 97在线公开视频 | 日干夜干天天干 | 国产日产久久高清欧美一区 | 国产亚洲精品线观看77 | 国产成人a一在线观看 | 波多野结衣精品一区二区三区 | 青青成人福利国产在线视频 | 香蕉视频污视频 | 久久精品国产亚洲高清 | 免费看黄视频 | 亚洲精品亚洲人成在线播放 | 男女一级特黄a大片 | 一个人看的www免费观看视频 | 在线不卡一区二区三区日韩 |