首页 >> 加油泵

计算机三级C语言上机试题总结之三0水泥泵

时间:2022/09/08 03:29:16 编辑:

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

计算机三级C语言上机试题总结(之三) 2011年12月10日 来源: 160915517.16

200个四位数之三(共四题)code:/*已知在文件IN.DAT中存有若干个(个数<200)四位数字的正整数, 函数ReadDat( )读取这若干个正整数并存入数组xx中。请编制函数Calvalue( ), 其功能要求: 1. 求出这文件中共有多少个正整数totNum; 2. 求这些数右移1位后, 产生的新数是奇数的数的个数totCnt, 以及满足此条件的这些数(右移前的值)的算术平均值totPjz。最后main()函数调用函数WriteDat()把所求的结果输出到文件OUT.DAT中。注意: 部分源程序存放在PROG1.C中。请勿改动数据文件IN.DAT中的任何数据,主函数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("数据文件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("OUT.DAT", "w") ;fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;fclose(fp) ;}

out.dat 文件内容应当如下:160805537.54

小于200个四位数之四(共四题)code:/*已知在文件IN.DAT中存有若干个(个数<200)四位数字的正整数, 函数ReadDat( )读取这若干个正整数并存入数组xx中。请编制函数Calvalue( ), 其功能要求: 1. 求出这文件中共有多少个正整数totNum; 2. 求这些数右移1位后, 产生的新数是偶数的数的个数totCnt, 以及满足此条件的这些数(右移前的值)的算术平均值totPjz。最后main()函数调用函数WriteDat()把所求的结果输出到文件OUT.DAT中。注意: 部分源程序存放在PROG1.C中。请勿改动数据文件IN.DAT中的任何数据,主函数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]>0; 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("数据文件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("OUT.DAT", "w") ;fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;fclose(fp) ;}

out.dat 文件内容应当如下:160805447.93

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

code:/*函数ReadDat( )实现从文件IN.DAT中读取一篇英文文章存入到字符串数组xx中; 请编制函数SortCharD( ), 其函数的功能是: 以行为单位对字符按从大到小的顺序进行排序, 排序后的结果仍按行重新存入字符串数组xx中。最后main()函数调用函数W

东莞市环航进出口贸易有限公司

佛山英之翼商务咨询有限公司

济南明朗不锈钢制品有限公司

福州市仓山区大升昌诚信便利店白云店

广州大恒自动化设备有限公司

永丰食品厂

旭升照明有限公司

台州泛亚进出口有限公司

北京拓乾商贸有限公司

泰州天达绳带有限公司

相关资讯