首頁 考試吧論壇 Exam8視線 考試商城 網絡課程 模擬考試 考友錄 實用文檔 求職招聘 論文下載 | ||
![]() |
2011中考 | 2011高考 | 2012考研 | 考研培訓 | 在職研 | 自學考試 | 成人高考 | 法律碩士 | MBA考試 MPA考試 | 中科院 |
|
![]() |
四六級 | 職稱英語 | 商務英語 | 公共英語 | 托福 | 雅思 | 專四專八 | 口譯筆譯 | 博思 | GRE GMAT 新概念英語 | 成人英語三級 | 申碩英語 | 攻碩英語 | 職稱日語 | 日語學習 | 法語 | 德語 | 韓語 |
|
![]() |
計算機等級考試 | 軟件水平考試 | 職稱計算機 | 微軟認證 | 思科認證 | Oracle認證 | Linux認證 華為認證 | Java認證 |
|
![]() |
公務員 | 報關員 | 銀行從業資格 | 證券從業資格 | 期貨從業資格 | 司法考試 | 法律顧問 | 導游資格 報檢員 | 教師資格 | 社會工作者 | 外銷員 | 國際商務師 | 跟單員 | 單證員 | 物流師 | 價格鑒證師 人力資源 | 管理咨詢師考試 | 秘書資格 | 心理咨詢師考試 | 出版專業資格 | 廣告師職業水平 駕駛員 | 網絡編輯 |
|
![]() |
衛生資格 | 執業醫師 | 執業藥師 | 執業護士 | |
![]() |
會計從業資格考試(會計證) | 經濟師 | 會計職稱 | 注冊會計師 | 審計師 | 注冊稅務師 注冊資產評估師 | 高級會計師 | ACCA | 統計師 | 精算師 | 理財規劃師 | 國際內審師 |
|
![]() |
一級建造師 | 二級建造師 | 造價工程師 | 造價員 | 咨詢工程師 | 監理工程師 | 安全工程師 質量工程師 | 物業管理師 | 招標師 | 結構工程師 | 建筑師 | 房地產估價師 | 土地估價師 | 巖土師 設備監理師 | 房地產經紀人 | 投資項目管理師 | 土地登記代理人 | 環境影響評價師 | 環保工程師 城市規劃師 | 公路監理師 | 公路造價師 | 安全評價師 | 電氣工程師 | 注冊測繪師 | 注冊計量師 |
|
![]() |
繽紛校園 | 實用文檔 | 英語學習 | 作文大全 | 求職招聘 | 論文下載 | 訪談 | 游戲 |
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) ;
}
北京 | 天津 | 上海 | 江蘇 | 山東 |
安徽 | 浙江 | 江西 | 福建 | 深圳 |
廣東 | 河北 | 湖南 | 廣西 | 河南 |
海南 | 湖北 | 四川 | 重慶 | 云南 |
貴州 | 西藏 | 新疆 | 陜西 | 山西 |
寧夏 | 甘肅 | 青海 | 遼寧 | 吉林 |
黑龍江 | 內蒙古 |