08-09_2C语言选修上机考试复习题.docVIP

  • 17
  • 0
  • 约1.45万字
  • 约 9页
  • 2016-10-08 发布于浙江
  • 举报
08-09_2C语言选修上机考试复习题

一、单项选择题 略 二、改错题(典型题型) 1、在考生文件夹下,给定程序MODI.C的功能是:从低位开始取出长整型变量s中奇数位上的数,依次构成一个新数放在t中。例如,当s中的数为:7654321时,t中的数为:7531。 请修改并运行该程序,然后将源程序文件MODI.C上传。 #include stdio.h main( ) { long s, t, sl=10; system(“CLS”); printf(\nPlease enter s:); scanf(%ld, s); /************found************/ t = s / 10; while ( s 0) { s = s/100; t = s%10 * sl + t; /************found************/ sl = sl*100; } printf(The result is: %ld\n, t); } 2、在考生文件夹下,给定程序MODI.C的功能是:求一维数组a中的值为偶数的元素之和。 例如,当一维数组a中的元素为:10,4,2,7,3,12,5,34,5,9 ,程序的输出应为:The result is: 62 请修改并运行该程序,然后将源程序文件MODI.C提交。 #include conio.h #include stdio.h main() { int a[10]={10,4,2,7,3,12,5,34,5,9},i,s; system(“CLS”); s = 0; for ( i=0; i10; i++) /************found************/ if (i % 2 == 0) s = s + a[i]; /************found************/ print(The result is: %d\n, s); } 3、在考生文件夹下,给定程序MODI.C的功能是:求一维数组a中值为偶数的元素之和。 例如,当一维数组a中的元素为:10,4,2,7,3,12,5,34,5,9 ,程序的输出应为:The result is: 62。 请修改并运行该程序,然后将源程序文件MODI.C提交。 #include stdio.h sum ( int arr[ ],int n ) { int i,s; system(“CLS”); s = 0; for ( i=0; in; i++) if (arr[i] % 2 == 0) /************found************/ s = s + i; return (s); } main() { int a[10]={10,4,2,7,3,12,5,34,5,9},i,s; /************found************/ s = sum( a ,2 ); printf(The result is: %d\n, s); } 4、在考生文件夹下,给定程序MODI.C的功能是: 求一维数组a中的最大元素及其下标。例如,当一维数组a中的元素为:1,4,2,7,3,12,5,34,5,9,程序的输出应为:The max is: 34,pos is: 7 。请修改并运行该程序,然后将源程序文件MODI.C提交。 #include conio.h #include stdio.h main() { int a[10]={1,4,2,7,3,12,5,34,5,9},i,max,pos; system(“CLS”); max = a[0]; pos = 0; for ( i=1; i10; i++) /************found************/ if (max a[i]) { max = a[i]; /************found************/ i = pos; } printf(The max is: %d ,pos is: %d\n, max , pos); } 5、在考生文件夹下,给定程序MODI.C的功能是:先将在字符串s中的字符按逆序存放到t串中,然后把s中的字符按正序连接到t串的后面。例如:当s中的字符串为:ABCDE时,则t中的字符串应为:EDCB

文档评论(0)

1亿VIP精品文档

相关文档