木塞厂家
免费服务热线

Free service

hotline

010-00000000
木塞厂家
热门搜索:
行业资讯
当前位置:首页 > 行业资讯

当计算机三级C语言上机试题总结之三

发布时间:2021-09-10 04:34:27 阅读: 来源:木塞厂家

计算机三级C语言上机试题总结(之三)

160

91

5517.16

200个四位数之三(共四题)

code:

/*

已知在文件T中存有若干个(个数 200)四位数字的正整

数, 函数ReadDat( )读取这若干个正整数并存入数组xx中。请编

制函数Calvalue( ), 其功能要求: 1. 求出这文件中共有多少个

正整数totNum; 2. 求这些数右移1位后, 产生的新数是奇数的数

的个数totCnt, 以及满足此条件的这些数(右移前的值)的算术平

均值totPjz。最后main()函数调用函数WriteDat()把所求的结果

输出到文件T中。

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

请勿改动数据文件T中的任何数据,主函数main()、读

数据函数ReadDat()和输出数据函数WriteDat()的内容。

*/

#include

#include

#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)

{/**/

for(; xx[totNum]; totNum++)

if((xx[totNum] 1)%2)

{ totCnt++; totPjz+=xx[totNum];}

if(totCnt) totPjz/=totCnt;

/**/

}

void main()

{

int i ;

clrscr() ;

for(i = 0 ; i MAXNUM ; i++) xx[i] = 0 ;

if(ReadDat()) {

printf("数据文件T不能打开!\007\n") ;

return ;

}

Calvalue() ;

printf("文件T中共有正整数=%d个\n", totNum) ;

printf("符合条件的正整数的个数=%d个\n", totCnt) ;

printf("平均值=%.2lf\n", totPjz) ;

WriteDat() ;

}

int ReadDat(void)

{

FILE *fp ;

int i = 0 ;

if((fp = fopen("t", "r")) == NULL) return 1 ;

while(!feof(fp)) {

fscanf(fp, "%d,", xx[i++]) ;

}

fclose(fp) ;

return 0 ;

}

void WriteDat(void)

{

FILE *fp ;

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

fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;

fclose(fp) ;

}

t 文件内容应当如下:

160

80

5537.54

小于200个四位数之四(共四题)

code:

/*

已知在文件T中存有若干个(个数 200)四位数字的正整

数, 函数ReadDat( )读取这若干个正整数并存入数组xx中。请编

制函数Calvalue( ), 其功能要求: 1. 求出这文件中共有多少个

正整数totNum; 2. 求这些数右移1位后, 产生的新数是偶数的数

的个数totCnt, 以及满足此条件的这些数(右移前的值)的算术平

均值totPjz。最后main()函数调用函数WriteDat()把所求的结果

输出到文件T中。

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

请勿改动数据文件T中的任何数据,主函数main()、读

数据函数ReadDat()和输出数据函数WriteDat()的内容。

*/

#include

#include

#define MAXNUM 200

int xx[MAXNUM] ;

int totNum = 0 ; /* 文件T中共有多少个正整数 */

int totCnt = 0 ; /* 符合条件的正整数的个数 */

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

int ReadDat(void) ;

void WriteDat(void) ;

void Calvalue(void)

{/**/

for(; xx[totNum] totNum++)

if((xx[totNum] 1)%2==0)

{ totCnt++; totPjz+=xx[totNum]; }

if(totCnt) totPjz/=totCnt;

/**/

}

void main()

{

int i ;

clrscr() ;

for(i = 0 ; i MAXNUM ; i++) xx[i] = 0 ;

if(ReadDat()) {

printf("数据文件T不能打开!\007\n") ;

return ;

}

Calvalue() ;

printf("文件T中共有正整数=%d个\n", totNum) ;

printf("符合条件的正整数的个数=%d个\n", totCnt) ;

printf("平均值=%.2lf\n", totPjz) ;

WriteDat() ;

}

int ReadDat(void)

{

FILE *fp ;

int i = 0 ;

if((fp = fopen("t", "两夹具以1定的速度分离并拉伸试样r")) == NULL) return 1 ;

while(!feof(fp)) {

fscanf(fp, "%d,", xx[i++]) ;

}

fclose(fp) ;

retu借助全省企业家培训、省外专局国外培训等培训渠道rn 0 ;

}

void WriteDat(void)

{

FILE *fp ;

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

fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;

fclose(fp) ;

}

t 文件内容应当如下:

160

80

5447.93

英文文章——字符串处理(共10题)

之一

code:

/*

函数ReadDat( )实现从文件T中读取一篇英文文章存入到

字符串数组xx中; 请编制函数SortCharD( ), 其函数的功能是: 以

行为单位对字符按从大到小的顺序进行排序, 排序后的结果仍按行

重新存入字符串数组xx中。最后main()函数调用函数提升品牌价值W

绵阳工作服制作
绵阳设计工作服
绵阳制作工作服
南充订制西装