- 相关推荐
浙江省计算机二级上机考试试题库
2017年3月计算机等级考试就要开考了,同学们准备好了吗?下面跟yjbys小编一起来看看最新的计算机二级考试题吧!
1. 数字处理(切割技术)
1-1找Armstrong(水仙花)数:371=3*3*3+7*7*7+1*1*1 【这是一个三位的自然数,要点是三位分离】
#include
#include
void main()
{ int i,a,b,c;
for(i=100;i<=999;i++)
{ a=i/100;
_______1_______ // b=i0/10;
c=i;
if (________2________) // a*a*a+b*b*b+c*c*c = = i
printf("%d is a Armstrong number!n",i);
}
}
1-2输入1个整数后,输出该数的位数。(例:输入3214则输出4,输入-23156则输出5)。【逐位剥离】
#include
void main()
{ int n,k=0;
scanf("%d",&n);
while( _____1_____ ){ // n!=0
k++;
_____2_____; // n=n/10
}
printf("%dn",k);
}
1-3求输入的整数各位数字之和,如输入234则输出9,输入-312则输出6。【逐位剥离】
#include
#include
void main()
{
int n,s=0;
scanf("%d",&n);
______ 1 ______ // if (n<0) n=-n;【符号预处理】
while(n!=0) {
______ 2 ______ // s+=n;
n=n/10;
}
printf("%dn",s);
}
1-4调用函数f,将一个整数首尾倒置。例如:若程序输入12345,则输出54321;若程序输入-34567,则输出-76543。【逐位剥离+逆置技术y=y*10+m 】
#include
#include
long f(long n)
{ long m,y=0; m=fabs(n);
while(m!=0) {
y=y*10+m;
____1____ // m=m/10 ;
}
if(n>=0) return y;
else _____2_____ // return -y ;
}
void main()
{
printf("%ldt",f(12345)); printf("%ldn",f(-34567));
}
1-5寻找并输出11至999之间的数m,它满足m、m*m、m*m*m均为回文数。说明:所谓回文数是指各位数字左右对称,例如121、676、94249等。满足上述条件的数如m=11,m^2=121,m^3=1331皆为回文数。
请编制函数int JSValue(long m)实现此功能,如果是回文数,则函数返回1,反之则返回0。最后把结果写入到考生文件夹中Paper子文件夹下的新建文件Design2.dat。【本题目的算法与 1-4题相同】
#include
#include
#include
int JSValue(long m)
{
long i,n;
n=m; i=0; // i中存放的是m的倒置数
while(n>0)
{ i=i*10+n; n=n/10; }
if (m = = i) return 1;
else return 0;
}
void main()
{
FILE *p;long m;
p=fopen("design.dat","w");
for(m=11;m<1000;m++)
{ if(JSValue(m)&&JSValue(m*m)&&JSValue(m*m*m))
fprintf(p,"%ld ",m); }
fclose(p); }
2. 字符串操作(特别,单字符删除的两种算法)
2-1输入一个小写字母,将字母循环后移5个位置后输出。例如:"a"变成"f","w"变成"b"。
#include
void main()
{ char c;
c=getchar();
if(______1______) // c>='a'&&c<='u'
c=c+5;
else
if (c>='v' && c<='z')
______2______ // c=(c-'a'+5)&+'a'; 或 c=c-21; 或 c=c+5-26;
putchar(c);
}
2-2输入一个字符串,将组成字符串的所有字符先按顺序存放到字符串t中,再将字符串中的字符按逆序连接到字符串t后面。例如:输入"ABCD",则字符串t为"ABCDDCBA"。PP2
#include
#include
void fun(char *s,char *t)
{ int i,sl;
sl=strlen(s);
for(i=0;i
t[i]=s[i];
for(i=0;i
t[sl+i]=s[sl-i]; // t[sl+i]=s[sl-1-i];
t[sl]=" "; // t[2*sl]=’ ’;
}
void main()
{ char s[100],t[100];
scanf("%s",s);
fun(s,t);
printf("%s",t);
}
2-3设计程序:计算字符串s中每个字符的权重值,所谓权重值就是字符在字符串中的位置值与该字符的ASCII码值的乘积。位置值从1开始依此递增。将每个字符的权重值,以格式"%d "写入到源程序目录中Paper子目录下的新建文件design.dat中。
#include
#include
void main()
{ FILE *p; int i,w;
char *s="we45*&y3r#$1";
p=fopen("design.dat","w");
for (i=0;s[i]!=' ';i++)
{ w=(i+1)*s[i];
fprintf( p,"%d ",w);
}
fclose(p);
}
2-4调用find函数在输入的字符串中查找是否出现"the"这个单词。如果查到返回出现的次数,如果未找到返回0。【本题解在判断源串里当前连续三个字符是否为"the"这个单词采用了查找算法】
#include
int find(char *str)
{ char *fstr="the";
int i=0,j,n=0;
while (str[i]!=' ') 【注:while (str[i+2]!=' ') 更佳】
{
for(______1______) // j=0; j<3; j++
if (str[j+i]!=fstr[j]) break;
if (______2______) n++; // j>=3 或者 j = = 3
i++;
}
return n;
}
void main()
{ char a[80];
gets(a);
printf("%d",find(a));
}
【注:以下为单字符删除。出现两种算法。一是使用strcpy做子串覆盖,二是逐个保留新串的字符】
2-5调用函数f,从字符串中删除所有的数字字符。
#include
#include
#include
void f(char *s)
{ int i=0;
while(s[i]!=' '){
if(isdigit(s[i])) ____1____(s+i,s+i+1); // strcpy
___2___ i++;} // else
}
void main()
{ char str[80];
gets(str); f(str); puts(str);
}
2-6将字符串s中所有的字符'c'删除。
#include
void main()
{ char s[80];
int i,j;
gets(s);
for(i=j=0; ______1______; i++) // s[i] != ' '
if(s[i] != 'c')
{ s[j]=s[i];
______2______ // j++;
}
s[j]=' ';
puts(s);
}
2-7输入一个字符串,将组成字符串的所有非英文字母的字符删除后输出。
#include
#include
void main()
{ char str[256];
int i,j,k=0,n;
gets(str);
n=strlen(str);
for(i=0;i
if (tolower(str[i])<'a' || tolower(str[i])>'z') // if (tolower(str[i])>='a' && tolower(str[i])<='z')
{
str[n]=str[i]; n++; // str[k]=str[i]; k++;
}
str[k]=' ';
printf("%sn",str);
3. 最大(小)值
3-1运行时输入10个数,然后分别输出其中的最大值、最小值。PP11
#include
void main()
{ float x,max,min; int i;
for(i=0;i<=10;i++) { // for(i=1; i<=10; i++) {
scanf("%f",&x);
if(i=1) { max=x;min=x;} // if(i==1) { max=x;min=x;}
if(x>max) max=x;
if(x
}
printf("%f,%fn",max,min);
}
3-2 对x=1,2,……,10,求f(x)=x*x-5*x+sin(x)的最大值。P3
#include
#include
#define f(x) x*x-5*x+sin(x)
void main()
{ int x; float max;
______1______ // max=f(1);
for(x=2;x<=10;x++)
______2______ // if (f(x)>max) max=f(x);
printf("%fn",max);
}
3-3对x=1,2,…10,求函数f(x)=x-10*cos(x)-5*sin(x)的最大值,并将该数以格式".3f"写入到考生文件夹中Paper子文件夹下的新建文件Design1.dat。
#include
#include
void main()
{ FILE *p; float f(float),max,x;
int i; max=f(1);
for (i=2;i<=10;i++)
{ x=f(i);
if (max
}
p=fopen("Design1.dat","w");
fprintf(p,"%.3f",max);
fclose(p);
}
float f(float x)
{ float t;
t=x-10*cos(x)-5*sin(x);
return t;
}
3-4 z=f(x,y)=(3.14*x-y)/(x+y),若x、y取值为区间[1,6]的整数,找出使z取最小值的x1、y1,并将x1、y1以格式"%d,%d"写入到考生文件夹中Paper子文件夹下的新建文件Design2.dat。P6
【浙江省计算机二级上机考试试题库】相关文章:
计算机二级考试题库及答案01-21
wps计算机二级考试题库10-24
浙江省计算机二级考试试题10-24
计算机二级C语言考试上机冲刺试题及答案03-03
计算机二级C上机考试试题及答案03-05
浙江省计算机一级考试题库05-30
全国计算机二级考试题库10-24
2016计算机二级VB上机考试试题题库03-07