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

網(wǎng)站首頁
分類導(dǎo)航
試題中心
下載中心
英語學(xué)習(xí)
繽紛校園
考試論壇
網(wǎng)站留言
客服中心
 1999年9月全國計(jì)算機(jī)等級考試四級機(jī)試試題及答案(已運(yùn)行通過)
【字體:
1999年9月全國計(jì)算機(jī)等級考試四級機(jī)試試題及答案(已運(yùn)行通過)
http://www.top-99.com.cn 來源:考試吧(Exam8.com) 點(diǎn)擊: 更新:2004-8-12
1./*PROG1 已知在文件IN.DAT中存有若干個(gè)(個(gè)數(shù)<200)四位數(shù)字的正整數(shù),
函數(shù)ReadDat()是讀取這若干個(gè)正整數(shù)并存入數(shù)組XX中。請編制函數(shù)CalValue(),
其功能要求:1、求出這文件中共有多少個(gè)正整數(shù)totNum;2、求出這些數(shù)中的
各位數(shù)字之和是偶數(shù)的數(shù)的個(gè)數(shù)totCnt,以及滿足此條件的這些數(shù)的算術(shù)平均
值totpjZ,最后調(diào)用函數(shù)WriteDat()把所求的結(jié)果輸出到文件OUT2.DAT中。
注意:部分部分源程序存放在PROG1.C中。
請勿改動(dòng)主函數(shù)main(),讀數(shù)據(jù)函數(shù)ReacdDat()和輸出數(shù)據(jù)函數(shù)WriteDat()的內(nèi)容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少個(gè)正整數(shù) */
int totCnt = 0 ; /* 符合條件的正整數(shù)的個(gè)數(shù) */
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("數(shù)據(jù)文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數(shù)=%d個(gè)\n", totNum) ;
printf("符合條件的正整數(shù)的個(gè)數(shù)=%d個(gè)\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中存有若干個(gè)(個(gè)數(shù)<200)四位數(shù)字的正整數(shù),
函數(shù)ReadDat()是讀取這若干個(gè)正整數(shù)并存入數(shù)組XX中。請編制函數(shù)CalValue(),
其功能要求:1、求出這文件中共有多少個(gè)正整數(shù)totNum;2、求出這些數(shù)右移
1位后,產(chǎn)生的新數(shù)是偶數(shù)的數(shù)的個(gè)數(shù)totCnt,以及滿足此條件的這些數(shù)(右移
前的值)的算術(shù)平均值totpjZ,最后調(diào)用函數(shù)WriteDat()把所求的結(jié)果輸出到
文件OUT4.DAT中。
注意:部分部分源程序存放在PROG2.C中。
請勿改動(dòng)主函數(shù)main(),讀數(shù)據(jù)函數(shù)ReacdDat()和輸出數(shù)據(jù)函數(shù)WriteDat()的內(nèi)容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少個(gè)正整數(shù) */
int totCnt = 0 ; /* 符合條件的正整數(shù)的個(gè)數(shù) */
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("數(shù)據(jù)文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數(shù)=%d個(gè)\n", totNum) ;
printf("符合條件的正整數(shù)的個(gè)數(shù)=%d個(gè)\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中存有若干個(gè)(個(gè)數(shù)<200)四位數(shù)字的正整數(shù),
函數(shù)ReadDat()是讀取這若干個(gè)正整數(shù)并存入數(shù)組XX中。請編制函數(shù)CalValue(),
其功能要求:1、求出這文件中共有多少個(gè)正整數(shù)totNum;2、求出這些數(shù)中的
個(gè)位數(shù)位置上的數(shù)字是3.6和9的數(shù)的數(shù)的個(gè)數(shù)totCnt,以及滿足此條件的這些
數(shù)的算術(shù)平均值totpjZ,最后調(diào)用函數(shù)WriteDat()把所求的結(jié)果輸出到文件
OUT5.DAT中。
注意:部分部分源程序存放在PROG3.C中。
請勿改動(dòng)主函數(shù)main(),讀數(shù)據(jù)函數(shù)ReacdDat()和輸出數(shù)據(jù)函數(shù)WriteDat()的內(nèi)容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少個(gè)正整數(shù) */
int totCnt = 0 ; /* 符合條件的正整數(shù)的個(gè)數(shù) */
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("數(shù)據(jù)文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數(shù)=%d個(gè)\n", totNum) ;
printf("符合條件的正整數(shù)的個(gè)數(shù)=%d個(gè)\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中存有若干個(gè)(個(gè)數(shù)<200)四位數(shù)字的正整數(shù),
函數(shù)ReadDat()是讀取這若干個(gè)正整數(shù)并存入數(shù)組XX中。請編制函數(shù)CalValue(),
其功能要求:1、求出這文件中共有多少個(gè)正整數(shù)totNum;2、求出這些數(shù)中的
千位數(shù)位置上的數(shù)字大于個(gè)位數(shù)位置上的數(shù)字的數(shù)的個(gè)數(shù)totCnt,以及滿足此
條件的這些數(shù)的算術(shù)平均值totpjZ,最后調(diào)用函數(shù)WriteDat()把所求的結(jié)果輸
出到文件OUT8.DAT中。
注意:部分部分源程序存放在PROG4.C中。
請勿改動(dòng)主函數(shù)main(),讀數(shù)據(jù)函數(shù)ReacdDat()和輸出數(shù)據(jù)函數(shù)WriteDat()的內(nèi)容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少個(gè)正整數(shù) */
int totCnt = 0 ; /* 符合條件的正整數(shù)的個(gè)數(shù) */
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("數(shù)據(jù)文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數(shù)=%d個(gè)\n", totNum) ;
printf("符合條件的正整數(shù)的個(gè)數(shù)=%d個(gè)\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中存有若干個(gè)(個(gè)數(shù)<200)四位數(shù)字的正整數(shù),
函數(shù)ReadDat()是讀取這若干個(gè)正整數(shù)并存入數(shù)組XX中。請編制函數(shù)CalValue(),
其功能要求:1、求出這文件中共有多少個(gè)正整數(shù)totNum;2、求出這些數(shù)中的
百位數(shù)位置上的數(shù)字是1、5和7的數(shù)的個(gè)數(shù)totCnt,以及滿足此條件的這些數(shù)的
算術(shù)平均值totpjZ,最后調(diào)用函數(shù)WriteDat()把所求的結(jié)果輸出到文件OUT7.DAT中。
注意:部分部分源程序存放在PROG5.C中。
請勿改動(dòng)主函數(shù)main(),讀數(shù)據(jù)函數(shù)ReacdDat()和輸出數(shù)據(jù)函數(shù)WriteDat()的內(nèi)容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少個(gè)正整數(shù) */
int totCnt = 0 ; /* 符合條件的正整數(shù)的個(gè)數(shù) */
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("數(shù)據(jù)文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數(shù)=%d個(gè)\n", totNum) ;
printf("符合條件的正整數(shù)的個(gè)數(shù)=%d個(gè)\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中存有若干個(gè)(個(gè)數(shù)<200)四位數(shù)字的正整數(shù),
函數(shù)ReadDat()是讀取這若干個(gè)正整數(shù)并存入數(shù)組XX中。請編制函數(shù)CalValue(),
其功能要求:1、求出這文件中共有多少個(gè)正整數(shù)totNum;2、求出這些數(shù)右移1
位后,產(chǎn)生的新數(shù)是奇數(shù)的數(shù)的個(gè)數(shù)totCnt,以及滿足此條件的這些數(shù)(右移前
的值)的算術(shù)平均值totpjZ,最后調(diào)用函數(shù)WriteDat()把所求的結(jié)果輸出到文件
OUT3.DAT中。
注意:部分部分源程序存放在PROG6.C中。
請勿改動(dòng)主函數(shù)main(),讀數(shù)據(jù)函數(shù)ReacdDat()和輸出數(shù)據(jù)函數(shù)WriteDat()的內(nèi)容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少個(gè)正整數(shù) */
int totCnt = 0 ; /* 符合條件的正整數(shù)的個(gè)數(shù) */
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("數(shù)據(jù)文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數(shù)=%d個(gè)\n", totNum) ;
printf("符合條件的正整數(shù)的個(gè)數(shù)=%d個(gè)\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中存有若干個(gè)(個(gè)數(shù)<200)四位數(shù)字的正整數(shù),
函數(shù)ReadDat()是讀取這若干個(gè)正整數(shù)并存入數(shù)組XX中。請編制函數(shù)CalValue(),
其功能要求:1、求出這文件中共有多少個(gè)正整數(shù)totNum;2、求出這些數(shù)中的
百位數(shù)位置上的數(shù)字小于十位數(shù)位置上的數(shù)字的數(shù)的個(gè)數(shù)totCnt,以及滿足此
條件的這些數(shù)的算術(shù)平均值totpjZ,最后調(diào)用函數(shù)WriteDat()把所求的結(jié)果輸
出到文件OUT9.DAT中。
注意:部分部分源程序存放在PROG7.C中。
請勿改動(dòng)主函數(shù)main(),讀數(shù)據(jù)函數(shù)ReacdDat()和輸出數(shù)據(jù)函數(shù)WriteDat()的內(nèi)容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少個(gè)正整數(shù) */
int totCnt = 0 ; /* 符合條件的正整數(shù)的個(gè)數(shù) */
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("數(shù)據(jù)文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數(shù)=%d個(gè)\n", totNum) ;
printf("符合條件的正整數(shù)的個(gè)數(shù)=%d個(gè)\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中存有若干個(gè)(個(gè)數(shù)<200)四位數(shù)字的正整數(shù),
函數(shù)ReadDat()是讀取這若干個(gè)正整數(shù)并存入數(shù)組XX中。請編制函數(shù)CalValue(),
其功能要求:1、求出這文件中共有多少個(gè)正整數(shù)totNum;2、求出這些數(shù)中的
十位數(shù)位置上的數(shù)字是2、4和8的數(shù)的個(gè)數(shù)totCnt,以及滿足此條件的這些數(shù)的
算術(shù)平均值totpjZ,最后調(diào)用函數(shù)WriteDat()把所求的結(jié)果輸出到文件OUT6.DAT中。
注意:部分部分源程序存放在PROG8.C中。
請勿改動(dòng)主函數(shù)main(),讀數(shù)據(jù)函數(shù)ReacdDat()和輸出數(shù)據(jù)函數(shù)WriteDat()的內(nèi)容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少個(gè)正整數(shù) */
int totCnt = 0 ; /* 符合條件的正整數(shù)的個(gè)數(shù) */
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("數(shù)據(jù)文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數(shù)=%d個(gè)\n", totNum) ;
printf("符合條件的正整數(shù)的個(gè)數(shù)=%d個(gè)\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中存有若干個(gè)(個(gè)數(shù)<200)四位數(shù)字的正整數(shù),
函數(shù)ReadDat()是讀取這若干個(gè)正整數(shù)并存入數(shù)組XX中。請編制函數(shù)CalValue(),
其功能要求:1、求出這文件中共有多少個(gè)正整數(shù)totNum;2、求出這些數(shù)中的
千位數(shù)位置上的數(shù)字與十位數(shù)位置上的數(shù)字均為奇數(shù)的數(shù)的個(gè)數(shù)totCnt,以及
滿足此條件的這些數(shù)的算術(shù)平均值totpjZ,最后調(diào)用函數(shù)WriteDat()把所求的
結(jié)果輸出到文件OUT10.DAT中。
注意:部分部分源程序存放在PROG9.C中。
請勿改動(dòng)主函數(shù)main(),讀數(shù)據(jù)函數(shù)ReacdDat()和輸出數(shù)據(jù)函數(shù)WriteDat()的內(nèi)容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少個(gè)正整數(shù) */
int totCnt = 0 ; /* 符合條件的正整數(shù)的個(gè)數(shù) */
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("數(shù)據(jù)文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數(shù)=%d個(gè)\n", totNum) ;
printf("符合條件的正整數(shù)的個(gè)數(shù)=%d個(gè)\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中存有若干個(gè)(個(gè)數(shù)<200)四位數(shù)字的正整數(shù),
函數(shù)ReadDat()是讀取這若干個(gè)正整數(shù)并存入數(shù)組XX中。請編制函數(shù)CalValue(),
其功能要求:1、求出這文件中共有多少個(gè)正整數(shù)totNum;2、求出這些數(shù)中的各
位數(shù)字之和是奇數(shù)的數(shù)的個(gè)數(shù)totCnt,以及滿足此條件的這些數(shù)的算術(shù)平均值
totpjZ,最后調(diào)用函數(shù)WriteDat()把所求的結(jié)果輸出到文件OUT1.DAT中。
注意:部分部分源程序存放在PROG10.C中。
請勿改動(dòng)主函數(shù)main(),讀數(shù)據(jù)函數(shù)ReacdDat()和輸出數(shù)據(jù)函數(shù)WriteDat()的內(nèi)容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

int xx[MAXNUM] ;
int totNum = 0 ; /* 文件IN.DAT中共有多少個(gè)正整數(shù) */
int totCnt = 0 ; /* 符合條件的正整數(shù)的個(gè)數(shù) */
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("數(shù)據(jù)文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數(shù)=%d個(gè)\n", totNum) ;
printf("符合條件的正整數(shù)的個(gè)數(shù)=%d個(gè)\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之間所有個(gè)位數(shù)字與十位數(shù)字之和
被10除所得余數(shù)恰是百位數(shù)字的素?cái)?shù)(如293)。計(jì)算并輸出上述這些素?cái)?shù)的個(gè)
數(shù)cnt以及這些素?cái)?shù)值的和sum。
請考生編寫函數(shù)countValue( )實(shí)現(xiàn)程序的要求,最后調(diào)用函數(shù)writeDAT( )把
結(jié)果cnt和sum輸出到文件out6.DAT中。
注意:部分源程序存放在PROG1.C中。
請勿改動(dòng)主函數(shù)main( )和輸出數(shù)據(jù)函數(shù)writeDAT( )的內(nèi)容。 */
#include <stdio.h>
int cnt, sum ;

void countValue()
{

}

void main()
{
cnt = sum = 0 ;

countValue() ;
printf("素?cái)?shù)的個(gè)數(shù)=%d\n", cnt) ;
printf("滿足條件素?cái)?shù)值的和=%d", sum) ;
writeDAT() ;
}

writeDAT()
{
FILE *fp ;

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


2. /* 編寫函數(shù)sumValue( ),它的功能是:計(jì)算正整數(shù)n的所有因子(1和n除外)之
和作為函數(shù)值返回。
例如:n=20時(shí),函數(shù)值為21。
函數(shù)ReadWrite( )是實(shí)現(xiàn)從文件in9.dat中讀取兩個(gè)字符串,并調(diào)用函數(shù)
sumValue(),最后把結(jié)果輸出到文件out9.dat中。
注意:部分源程序存在文件PROG1.C中,請勿改動(dòng)主函數(shù)main()和其它函數(shù)
中的任何內(nèi)容,僅在函數(shù)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("數(shù)據(jù)文件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./* 請編寫一個(gè)函數(shù)changeStr(char *s),函數(shù)的功能是把s串中所有的字
母改寫成該字母的下一個(gè)字母,字母z改寫成字母a。大寫仍為大寫字母,
小寫字母仍為小寫字母,其它的字符不變。
函數(shù)ReadWrite()實(shí)現(xiàn)從文件in2.dat中讀取兩個(gè)字符串,并調(diào)用函
數(shù)changestr(),最后把結(jié)果輸出到文件out2.dat中。
注意:部分源程序存在文件PROG1.C中。請勿改動(dòng)主函數(shù)main()和其
它函數(shù)中的任何內(nèi)容,僅在函數(shù)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的一個(gè)實(shí)根。
Xn+1=cos(Xn)
迭代步驟如下:
(1) 取x1初步值為0.0;
(2) x0=x1,把x1,把x1的值賦給x0;
(3) x1=cos(x0),求出一個(gè)新的x1;
(4) 若x0-x1的絕對值小于0.000001,執(zhí)行步驟(5),否則執(zhí)行步驟(2);
(5) 所求x1就是方程cos(x)-x=0的一個(gè)實(shí)根,作為函數(shù)值返回。
請編寫函數(shù)countValue()實(shí)現(xiàn)程序的要求,最后調(diào)用函數(shù)writeDAT()把
結(jié)果輸出到文件out4.dat中。
注意:部分源程序存在文件PROG1.C中,請勿改動(dòng)主函數(shù)main()和輸出數(shù)
據(jù)函數(shù)WriteDAT()的內(nèi)容。 */
#include <conio.h>
#include <math.h>
#include <stdio.h>
float countValue()
{

}

main()
{
clrscr();
printf("實(shí)根=%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中存有若干個(gè)(個(gè)數(shù)<200)四位數(shù)字的正整數(shù),
函數(shù)ReadDAT()讀取這些正整數(shù)并存入數(shù)組xx中。
請編制函數(shù)CalValue()其功能要求是:1.求出這個(gè)文件中共有多
少個(gè)正整數(shù)totNum;2.求出這些數(shù)中的各位數(shù)字之和是奇數(shù)的數(shù)的個(gè)
數(shù)totCnt,以及不滿足此條件的所有數(shù)的算術(shù)平均值totPjz,最后調(diào)
用函數(shù)WriteDAT()把所求的結(jié)果輸出到文件OUT8.DAT中。
注意:部分源程序存放在PROG1.C中。
請勿改動(dòng)主函數(shù)main(),讀數(shù)據(jù)函數(shù)ReadDAT()和輸出數(shù)據(jù)函數(shù)
WriteDAT()的內(nèi)容。 */
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

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

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

void CalValue(void)
{

}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數(shù)據(jù)文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數(shù)=%d個(gè)\n", totNum) ;
printf("符合條件的正整數(shù)的個(gè)數(shù)=%d個(gè)\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./* 編寫一個(gè)函數(shù)findstr(),該函數(shù)統(tǒng)計(jì)一個(gè)長度為2的子字符串在另一個(gè)
字符串中出現(xiàn)的次數(shù)。例如,假定輸入的字符串為“asd asasdfg asd as
zx67 asd mklo”,子字符串為“as”,則輸出6。
函數(shù)ReadWrite()實(shí)現(xiàn)從文件in1.dat中讀取兩個(gè)字符串,并調(diào)用函數(shù)
findStr(),最后把結(jié)果輸出到文件out1.dat中。
注意:部分源程序存在文件PROG1.C中。請勿改動(dòng)主函數(shù)main()和其它
函數(shù)中的任何內(nèi)容,僅在函數(shù)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./* 請編寫函數(shù)Void countValue(int *a,int *n),它的功能是:
求出1到1000之內(nèi)能被7或11整除但不能同時(shí)被7和11整除的所有整數(shù),
并放在數(shù)組a中,然后通過n返回這些數(shù)的個(gè)數(shù)。
注意:部分源程序存入在PROG1.C中。
請改動(dòng)主函數(shù)main()和輸入輸出數(shù)據(jù)函數(shù)WriteDAT()的內(nèi)容。*/
#include <stdio.h>
int cnt, sum ;

void countValue()
{

}

void main()
{
cnt = sum = 0 ;

countValue() ;
printf("素?cái)?shù)的個(gè)數(shù)=%d\n", cnt) ;
printf("滿足條件素?cái)?shù)值的和=%d", sum) ;
writeDAT() ;
}

writeDAT()
{
FILE *fp ;

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

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

void countValue()
{

}

void main()
{
cnt = sum = 0 ;

countValue() ;
printf("素?cái)?shù)的個(gè)數(shù)=%d\n", cnt) ;
printf("滿足條件素?cái)?shù)值的和=%d", sum) ;
writeDAT() ;
}

writeDAT()
{
FILE *fp ;

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


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

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

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

void CalValue(void)
{

}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數(shù)據(jù)文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有正整數(shù)=%d個(gè)\n", totNum) ;
printf("符合條件的正整數(shù)的個(gè)數(shù)=%d個(gè)\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個(gè)實(shí)數(shù)(N<200),函數(shù)ReadDAT()讀取
這N個(gè)實(shí)數(shù)并存入數(shù)組XX中。
請編制函數(shù)CalValue(),其功能要求是:1.求出這N個(gè)實(shí)數(shù)的平
均值aver;2.分別求出這N個(gè)實(shí)數(shù)的整數(shù)部分值的平均值averint以
及其小數(shù)部分值的平均值averdel,最后調(diào)用函數(shù)WriteDAT()把所求
的結(jié)果輸出到文件out10.DAT中。
注意:部分源程序存放在文件PROG1.C中。
請勿改動(dòng)主函數(shù)main(),讀數(shù)據(jù)函數(shù)ReadDAT()和輸出數(shù)據(jù)函數(shù)
WreitDAT的內(nèi)容。*/
#include <stdio.h>
#include <conio.h>
#define MAXNUM 200

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

void CalValue(void)
{

}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("數(shù)據(jù)文件IN.DAT不能打開!\007\n") ;
return ;
}
CalValue() ;
printf("文件IN.DAT中共有實(shí)數(shù)%d個(gè)\n", N) ;
printf("平均值=%.2lf\n", aver) ;
printf("整數(shù)部分值的平均值=%.2lf\n", averint) ;
printf("小數(shù)部分值的平均值=%.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) ;
}    

文章錄入:蕭雨    責(zé)任編輯:蕭雨  
  • 上一篇文章:

  • 下一篇文章:
  •  版權(quán)聲明
       如果本網(wǎng)站所轉(zhuǎn)載內(nèi)容不慎侵犯了您的權(quán)益,請與我們聯(lián)系,我們將會(huì)及時(shí)處理。如轉(zhuǎn)載本網(wǎng)內(nèi)容,請注明出處。
     發(fā)表評論
    關(guān)于本站 網(wǎng)站聲明 廣告服務(wù)  聯(lián)系方式  付款方式  站內(nèi)導(dǎo)航  客服中心  友情鏈接   
    Copyright © 2004-2006 考試吧 (Exam8.com) All Rights Reserved 
    中國科學(xué)院研究生院中關(guān)村園區(qū)(北京市海淀區(qū))
    主站蜘蛛池模板: 天堂中文在线乱码 | 亚洲日本久久一区二区va | 午夜私人影院在线观看 | 色喔喔| 亚洲成人18 | 免费观看日批视频 | 免费一级欧美在线观看视频片 | 免费大片在线观看www | 北条麻妃中文字幕在线观看 | 亚洲人色大成年网站在线观看 | 久久久久国产精品免费看 | 国产高清在线不卡 | 伊人射 | 国产日韩免费视频 | 日韩成人影院 | 夜夜爽夜夜叫夜夜高潮漏水 | 人人艹人人| a级成人毛片久久 | 国产成人精品久久亚洲高清不卡 | 欧美性猛交ⅹxxx乱大交禽 | 深夜福利剧场 | 一级性片 | 国产精品免费入口视频 | 成人黄色三级视频 | 天堂成人精品视频在线观 | 久草网免费 | 国产精品自产拍在线观看 | 久久r这里只有精品 | 波多野结衣手机在线视频 | 手机看片1024久久精品你懂的 | 亚洲国产成人91精品 | 色哟哟在线网站 | 欧美日韩在线国产 | 亚洲国产日韩欧美在线a乱码 | 日日热| 韩日免费视频 | 动漫精品成人免费网站 | 新午夜影院 | 欧美一区二区视频在线观看 | 日韩视频第一页 | 成人午夜毛片 |