计算机三级网络技术机试100题和答案内容摘要:

n(, w)。 for(i = 0。 i maxline。 i++) { printf(%s\n, xx[i])。 fprintf(fp, %s\n, xx[i])。 } fclose(fp)。 } 【答案】 void StrCharJR(void) { int i,j,str1。 for(i=0。 imaxline。 i++) { str1=strlen(xx[i])。 /*计算各行字符串的长度 */ for(j=0。 jstr1。 j++) xx[i][j]+=xx[i][j]4。 /*字符的 ASCII值右移 4位再加上原字符的 ASCII值,得到新字符 */ } } 9. 函数 ReadDat() 的功能是实现从文件 , 存入到字符串数组 xx中。 请编制函数 encryptChar(),按给定的替代关系对数组 xx中的所有字符进行替代,仍存入数组 xx的对应的位置上,最后调用函数 WriteDat()把结果 xx输出到文件。 替代关系: f(p)=p*11 mod 256( p是数组 xx中某一个字符的 ASCII值, f(p)是计算后新字符的 ASCII值),如果原字符的 ASCII值是偶数或计算后 f(p)的值小于等于 32,则该字符不变,否则将 f(p)所对应的字符进行替代。 原始数据文件存放的格式是:每行的宽度均小于 80个字符。 请勿改动主函数 main()、读函数 ReadDat()和写函数 WriteDat()的内容。 试题程序: include include include include unsigned char xx[50][80]。 int maxline = 0。 /* 文章的总行数 */ int ReadDat(void)。 void WriteDat(void)。 void encryptChar() { } main() { clrscr()。 if(ReadDat()) { printf(数据文件 !\n\007)。 return。 } encryptChar()。 WriteDat()。 } int ReadDat(void) { FILE *fp。 int i= 0。 unsigned char *p。 if ((fp = fopen(,r)) ==NULL) return 1。 while(fgets(xx[i], 80, fp) !=NULL) { p = strchr(xx[i], 39。 \n39。 )。 if(p) *p = 0。 i++。 } maxline = i。 fclose(fp)。 return 0。 } void WriteDat(void) { FILE *fp。 int i。 fp = fopen(, w)。 for(i = 0。 i maxline。 i++) { printf(%s\n, xx[i])。 fprintf(fp, %s\n, xx[i])。 } fclose(fp)。 } 【答案】 void encryptChar() { int i。 char *pf。 for(i=0。 imaxline。 i++) { pf=xx[i]。 /*指针 pf指向当前行的首地址 */ while(*pf!=0) { if(*pf%2==0 || *pf*11%256=32)。 /*如果原字符的 ASCII值是偶数或计算后的值小于等于 32,则该字符不变 */ ////////// else *pf=*pf*11%256。 /*否则将所对应的 字符进行替代 */ pf++。 /*指针 pf指向下一个字符 */ } } } 10. 编写函数 jsValue(), 它的功能是求 Fibonacci数列中大于 t的最小的一个数 , 结果由函数返回 , 其中Fibonacci数列 F(n)的定义为 : F(0)=0, F(1)=1 F(n)=F(n1)+F(n2) 最后调用函数 writeDat(), 把结果输出到文件。 例如 : 当 t = 1000时 , 函数值为 1597。 请勿改动主 函数 main()和写函数 WriteDat()的内容。 试题程序: include int jsValue(int t) { } main() { int n。 n=1000。 printf(n=%d, f=%d\n, n, jsValue(n))。 writeDat()。 } writeDat() { FILE *in, *out。 int n,s。 out = fopen(, w)。 s = jsValue(1000)。 printf(%d,s)。 fprintf(out, %d\n, s)。 fclose(out)。 } 【答案】 int jsValue(int t) { int f1=0,f2=1,fn。 fn=f1+f2。 while(fn=t) {f1=f2。 f2=fn。 fn=f1+f2。 } /*如果当前的 Fibonacci数不大于 t,则计算下一个 Fibonacci数 */ ////////////////////////////////// return fn。 /*返回 Fibonacci数列中大于 t的最小的一个数 */ } 11. 请编写函数 countValue(), 它的功能是 : 求 n以内 ( 不包括 n) 同时能被 3与 7整除的所有自然数之和的平方根 s, 并作为函数值返回 , 最后结果 s输出到文件。 例如,若 n为 1000时,函数值应为 s=。 注意:部分源程序已给出。 请勿改动主函数 main()和输入输出函数 progReadWrite()的内容。 试题程序: include include include double countValue(int n) { } main() { clrscr()。 printf(自然数之和的平方根 =%f\n, countValue(1000))。 progReadWrite()。 } progReadWrite() { FILE *wf。 int i, n。 float s。 wf = fopen(, w)。 s = countValue(1000)。 fprintf(wf, %f\n, s)。 fclose(wf)。 } 【答案】 double countValue(int n) { double xy=。 int i。 for(i=1。 in。 i++) if(i%3==0 amp。 amp。 i%7==0) xy+=i。 /*求 n以内 (不包括 n)同时能被 3与 7整除的所有自然数之和 */ xy=sqrt((double)xy)。 /*再对总和求平方根 */ return xy。 } 12. 下列程序的功能是:在 3位整数( 100至 999)中寻找符合下面条件的整数,并依次从小到大存入数组 b中;它既是完全平方数,又有两位数字相同, 例如 144, 676等。 请编制函数 int jsValue(int bb[])实现此功能,满足该条件的整数的个数通过所编制的函数返回。 最后调用函数 writeDat()把结果输出到文件。 勿改动主函数 main()和写函数 writeDat()的内容。 试题程序: include int jsValue(int bb[ ]) { } main() { int b[20], num。 num = jsValue(b)。 writeDat(num, b)。 } writeDat(int num, int b[]) { FILE *out。 int i。 out = fopen(, w)。 fprintf(out, %d\n, num)。 for(i = 0。 i num。 i++) fprintf(out, %d\n, b[i])。 fclose(out)。 } 【答案】 int jsValue(int bb[ ]) { int i,j,k=0。 int hun,ten,data。 for(i=100。 i=999。 i++) { j=10。 while(j*j=i) { if (i==j*j) /*如果该数是完全平方数 */ { hun=i/100。 /*求该数的百位数字 */ data=ihun*100。 /*得到后两位数 */ ten=data/10。 /*求该数的十位数字 */ data=dataten*10。 /*求该数的个位数字 */ if(hun==ten || hun==data || ten==data) /*有两位数字相同 */ {bb[k]=i。 /*则把该数存入数组 bb中 */ k++。 } /*统计满足条件的数的个数 */ } j++。 } } return k。 /*返回满足该条件的整数的个数 */ } 13. 已知在文件 ( 个数 200) 4位数字的正整数 , 函数 ReadDat() 的功能是读取这若干个正整数并存入数组 xx中。 请编制函数 CalValue(),其功能要求:( 1)求出该文件中共有多少个正整数 totNum;( 2)求这些数右移 1位后,产生的新数是偶数的数的个数 totCnt,以及满足此条件的这些数(右移前的值)的算术平均值 totPjz,最后调用函数 WriteDat()把所求的结果输出到文件。 请勿改动主函数 main()、读函数 ReadDat()和写函数 WriteDat()的内容。 试题程序: include include define MAXNUM 200 int xx[MAXNUM]。 int totNum = 0。 /* 文件 */ int totCnt = 0。 /* 符合条件的正整数的个数 */ double totPjz =。 /* 平均值 */ int ReadDat(void)。 void Writedat(void)。 void CalValue(void) { } main() { int i。 clrscr()。 for(i = 0。 i MAXNUM。 i++) xx[i] = 0。 if(ReadDat()) { printf(数据文件 !\007\n)。 return。 } CalValue()。 printf(文件 = %d 个 \n, totNum)。 printf(符合条件的正整数的个数 = %d 个 \n, totCnt)。 printf(平均值 =%.2lf\n, totPjz)。 Writedat()。 } int ReadDat(void) { FILE *fp。 int i = 0。 if((fp = fopen (, r)) == NULL) return 1。 while(! feof(fp)) { fscanf(fp, %d, amp。 xx[i++])。 } fclose(fp)。 return 0。 } void WriteDat(void) { FILE *fp。 fp = fopen(, w)。 fprintf(fp, %d\n%d\n%.2lf\n, totNum, totCnt, totPjz)。 fclose(fp)。 } 【答案】 void CalValue(void) { int i,data。 for(i=0。 iMAXNUM。 i++) { if(!xx[i]) continue。 /*如果当前数为 0,则结束本次循环,取下一个数 */ if(xx[i]0) totNum++。 /*统计正整数的个数 */ data=xx[i]1。 /*将数右移一位 */ if (data%2==0) /*如果右移 1位后,产生的新数是偶数 */ { totCnt++。 totPjz+=xx[i]。 } /*统计这些数的个数,并将满足条件的原数求和 */ } totPjz/=totCnt。 /*求满足条件的这些数 (右移前的值 )的算术平均值 */ } 14. 已知数据文件 200个 4位数,并已调用读函数 readDat() 把这些数存入数组 a中,请编制一个函数 jsVal(),其功能是:把千位数字和十位数字重新组成一个新的十位数 ab(新十。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。