2011全国计算机等级考试c++上机试题1
日期:12-29| http://www.59wj.com |二级C++上机题库|人气:466次
2011全国计算机等级考试c++上机试题1
一、填空题
请补充函数fun,该函数的功能是:统计所有小于等于x(x>2)的素数的个数,素数的个数作为函数值返回。例如,输入x=20,结果:2,3,5,7,11,13,17,19。
请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。
注意:部分源程序给出如下。
# include <stdio.h>
int fun(int x)
{
int i,j,count=0;
printf("“nThe prime number between 2 to %d“n",x);
for(i=2;i<=x;i++)
{
for(___1___;j<i;j++)
if(___2___%j==0)
break;
if(___3___>=i)
{
count++;
printf(count%15 ? "%5d" : "“n%5d",i);
}
}
return count;
main()
{
int x=20,result;
result=fun(x);
printf("“nThe number of prime is : %d“n",result);
}
二、改错题
下列给定程序中函数fun的功能是:计算m!。例如,给m输入3,则输出6.000000。
请修改程序中的错误,使程序能输出正确的结果。
注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。
# include <stdio.h>
# include <conio.h>
double fun(int m)
{
double result=1.0;
/********error********/
if m==0
return 1.0;
while(m>1 && m<170)
/*******error*********/
result=m--;
return result;
}
main()
{
int m;
printf("Input m:");
scanf("%d",&m);
printf("“n“n%d!=%1f“n“n",m,fun(m));
}
www.59wj.com
三、编程题
学生的记录由学生和成绩组成,M名学生的数据已在主函数中放入结构体数组stu中,请编写函数fun,它的功能是:把分数最高的学生数据放在high所指的数组中,注意:分数最高的学生可能不止一个,函数返回分数最高的学生的人数。
请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
注意:部分源程序给出如下。
# include <stdio.h>
# define M 10
typedef struct
{
char num[10];
int s;
} SCORE;
int fun(SCORE *p,SCORE *q)
{
}
main ()
{
SCORE stu[M]={{"02",69},{"04",85},
{"01",91},{"08",64},{"06",87},{"015",85},{"013",91},{"012",64},{"011",91},{"017",64}};
SCORE high[M];
int i,n;
FILE *out;
n=fun(stu,high);
printf("The %d high score :“n",n);
for(i=0;i<n;i++)
printf("%s %4d“n",high[i].num,
high[i].s);
printf("“n");
out=fopen ("outfile.dat","w");
fprintf(out,"%d“n",n);
for(i=0;i<n;i++)
fprintf(out,"%4d“n",high[i].s);
fclose (out);
}
980
www.59wj.com
如果觉得《2011全国计算机等级考试c++上机试题1》二级C++上机题库,jsj不错,可以推荐给好友哦。
本文Tags: 计算机等级考试 - 上机题库 - 二级C++上机题库,jsj,