资源描述
校园网·新视野教育二级C上机考试复习资料 V16.0
(共50套题目)
第1套 校园网·新视野教育上机考试复习资料
1、程序填空题
#include <stdio.h>
#include <math.h>
double fun(double x)
{ double f, t; int n;
f = 1.0 + x;
/**********found**********/
t = ___1___;
n = 1;
do {
n++;
/**********found**********/
t *= (-1.0)*x/___2___;
f += t;
}
/**********found**********/
while (___3___ >= 1e-6);
return f;
}
main()
{ double x, y;
x=2.5;
y = fun(x);
printf("\nThe result is :\n");
printf("x=%-12.6f y=%-12.6f\n", x, y);
}
2、程序修改题
#include <stdio.h>
long fun(int x,int y,long *p )
{ int i;
long t=1;
/**************found**************/
for(i=1; i<y; i++)
t=t*x;
*p=t;
/**************found**************/
t=t/1000;
return t;
}
main()
{ long t,r; int x,y;
printf("\nInput x and y: "); scanf("%ld%ld",&x,&y);
t=fun(x,y,&r);
printf("\n\nx=%d, y=%d, r=%ld, last=%ld\n\n",x, y,r,t );
}
3、程序设计题 校园网·新视野教育上机考试复习资料
#include <stdio.h>
#include <math.h>
double fun(double x)
{
}
main()
{ double x,s;
printf("Input x: "); scanf("%lf",&x);
s=fun(x);
printf("s=%f\n",s);
}
第2套 校园网·新视野教育上机考试复习资料
1、程序填空题
#include <stdio.h>
int c1,c2,c3;
void fun(long n)
{ c1 = c2 = c3 = 0;
while (n) {
/**********found**********/
switch(___1___)
{
/**********found**********/
case 1: c1++;___2___;
/**********found**********/
case 2: c2++;___3___;
case 3: c3++;
}
n /= 10;
}
}
main()
{ long n=123114350L;
fun(n);
printf("\nThe result :\n");
printf("n=%ld c1=%d c2=%d c3=%d\n",n,c1,c2,c3);
}
2、程序修改题 校园网·新视野教育上机考试复习资料
#include <stdio.h>
int fun(unsigned n, int *zero)
{ int count=0,max=0,t;
do
{ t=n%10;
/**************found**************/
if(t=0)
count++;
if(max<t) max=t;
n=n/10;
}while(n);
/**************found**************/
zero=count;
return max;
}
main()
{ unsigned n; int zero,max;
printf("\nInput n(unsigned): "); scanf("%d",&n);
max = fun( n,&zero );
printf("\nThe result: max=%d zero=%d\n",max,zero);
}
3、程序设计题 校园网·新视野教育上机考试复习资料
#include <stdio.h>
double fun(int n)
{
}
main()
{ int n; double s;
printf("\nInput n: "); scanf("%d",&n);
s=fun(n);
printf("\n\ns=%f\n\n",s);
}
第3套 校园网·新视野教育上机考试复习资料
1、程序填空题
#include <stdio.h>
unsigned long fun(unsigned long n)
{ unsigned long x=0; int t;
while(n)
{ t=n%10;
/**********found**********/
if(t%2==__1__)
/**********found**********/
x=__2__+t;
/**********found**********/
n=__3__;
}
return x;
}
main()
{ unsigned long n=-1;
while(n>99999999||n<0)
{ printf("Please input(0<n<100000000): "); scanf("%ld",&n); }
printf("\nThe result is: %ld\n",fun(n));
}
2、程序修改题 校园网·新视野教育上机考试复习资料
#include <stdio.h>
void fun (long s, long *t)
{ int d;
long sl=1;
/************found************/
t = 0;
while ( s > 0)
{ d = s%10;
/************found************/
if (d%2 == 0)
{ *t = d * sl + *t;
sl *= 10;
}
s /= 10;
}
}
main()
{ long s, t;
printf("\nPlease enter s:"); scanf("%ld", &s);
fun(s, &t);
printf("The result is: %ld\n", t);
}
3、程序设计题 校园网·新视野教育上机考试复习资料
#include <stdio.h>
void fun(char p1[], char p2[])
{
}
main()
printf("Enter s1 and s2:\n") ;
scanf("%s%s", s1, s2) ;
printf("s1=%s\n", s1) ;
printf("s2=%s\n", s2) ;
printf("Invoke fun(s1,s2):\n") ;
fun(s1, s2) ;
printf("After invoking:\n") ;
printf("%s\n", s1) ;
}
第4套 校园网·新视野教育上机考试复习资料
1、程序填空题
#include <stdio.h>
#define M 3
#define N 4
void fun(int (*a)[N])
{ int i=0,j,find=0,rmax,c,k;
while( (i<M) && (!find))
{ rmax=a[i][0]; c=0;
for(j=1; j<N; j++)
if(rmax<a[i][j]) {
/**********found**********/
rmax=a[i][j]; c= __1__ ; }
find=1; k=0;
while(k<M && find) {
/**********found**********/
if (k!=i && a[k][c]<=rmax) find= __2__ ;
k++;
}
if(find) printf("find: a[%d][%d]=%d\n",i,c,a[i][c]);
/**********found**********/
__3__ ;
}
if(!find) printf("not found!\n");
}
main()
{ int x[M][N],i,j;
printf("Enter number for array:\n");
for(i=0; i<M; i++)
for(j=0; j<N; j++) scanf("%d",&x[i][j]);
printf("The array:\n");
for(i=0; i<M; i++)
{ for(j=0; j<N; j++) printf("%3d",x[i][j]);
printf("\n\n");
}
fun(x);
}
2、程序修改题 校园网·新视野教育上机考试复习资料
#include <stdio.h>
double fun ( int m )
{ double y = 1.0 ;
int i ;
/**************found**************/
for(i = 2 ; i < m ; i++)
/**************found**************/
y -= 1 /(i * i) ;
return( y ) ;
}
main( )
{ int n = 5 ;
printf( "\nThe result is %lf\n", fun ( n ) ) ;
}
3、程序设计题 校园网·新视野教育上机考试复习资料
#include <stdio.h>
#include <string.h>
int fun(int score[], int m, int below[])
{
}
main( )
int score[9] = {10, 20, 30, 40, 50, 60, 70, 80, 90} ;
n = fun(score, 9, below) ;
printf( "\nBelow the average score are: " ) ;
for (i = 0 ; i < n ; i++) printf("%d ", below[i]) ;
}
第5套 校园网·新视野教育上机考试复习资料
1、程序填空题
#include <stdio.h>
#include <string.h>
#define N 5
#define M 10
/**********found**********/
void fun(char (*ss) __1__, int k)
{ int i=0 ;
/**********found**********/
while(i< __2__) {
/**********found**********/
ss[i][k]=__3__; i++; }
}
main()
{ char x[N][M]={"Create","Modify","Sort","skip","Delete"};
int i;
printf("\nThe original string\n\n");
for(i=0;i<N;i++)puts(x[i]); printf("\n");
fun(x,4);
printf("\nThe string after deleted :\n\n");
for(i=0; i<N; i++) puts(x[i]); printf("\n");
}
2、程序修改题 校园网·新视野教育上机考试复习资料
#include <math.h>
#include <stdio.h>
double fun(double eps)
{ double s,t; int n=1;
s=0.0;
/************found************/
t=0;
while( t>eps)
{ s+=t;
t=t * n/(2*n+1);
n++;
}
/************found************/
return(s);
}
main()
{ double x;
printf("\nPlease enter a precision: "); scanf("%lf",&x);
printf("\neps=%lf, Pi=%lf\n\n",x,fun(x));
}
3、程序设计题 校园网·新视野教育上机考试复习资料
#include <stdio.h>
void fun( char *a, int n )
{
/* 以下代码仅供参考 */
int i=0,j,k=0;
while(a[k]=='*') k++; /* k为统计*字符个数 */
if(k>n)
{
i=n;j=k;
/* 以下完成将下标为k至串尾的字符前移k-n个位置 */
}
}
main()
printf("Enter a string:\n");gets(s);
printf("Enter n : ");scanf("%d",&n);
fun( s,n );
printf("The string after deleted:\n");puts(s);
}
第6套 校园网·新视野教育上机考试复习资料
1、程序填空题
#include <stdio.h>
#define N 4
/**********found**********/
void fun(int (*t)___1___ )
{ int i, j;
for(i=1; i<N; i++)
{ for(j=0; j<i; j++)
{
/**********found**********/
___2___ =t[i][j]+t[j][i];
/**********found**********/
___3___ =0;
}
}
}
main()
{ int t[][N]={21,12,13,24,25,16,47,38,29,11,32,54,42,21,33,10}, i, j;
printf("\nThe original array:\n");
for(i=0; i<N; i++)
{ for(j=0; j<N; j++) printf("%2d ",t[i][j]);
printf("\n");
}
fun(t);
printf("\nThe result is:\n");
for(i=0; i<N; i++)
{ for(j=0; j<N; j++) printf("%2d ",t[i][j]);
printf("\n");
}
}
2、程序修改题 校园网·新视野教育上机考试复习资料
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
/************found************/
#define FU(m,n) (m/n)
float fun(float a,float b,float c)
{ float value;
value=FU(a+b,a-b)+FU(c+b,c-b);
/************found************/
Return(Value);
}
main()
{ float x,y,z,sum;
printf("Input x y z: ");
scanf("%f%f%f",&x,&y,&z);
printf("x=%f,y=%f,z=%f\n",x,y,z);
if (x==y||y==z){printf("Data error!\n");exit(0);}
sum=fun(x,y,z);
printf("The result is : %5.2f\n",sum);
}
3、程序设计题 校园网·新视野教育上机考试复习资料
#include <stdio.h>
void fun( char *a )
{
}
main()
{ char s[81];
printf("Enter a string:\n");gets(s);
fun( s );
printf("The string after deleted:\n");puts(s);
}
第7套 校园网·新视野教育上机考试复习资料
1、程序填空题
#include <stdio.h>
#define N 3
#define M 4
/**********found**********/
void fun(int (*a)[N], int __1__)
{ int i,temp ;
/**********found**********/
for(i = 0 ; i < __2__ ; i++)
{ temp=a[0][i] ;
/**********found**********/
a[0][i] = __3__ ;
a[k][i] = temp ;
}
}
main()
{ int x[M][N]={ {1,2,3},{4,5,6},{7,8,9},{10,11,12} },i,j;
printf("The array before moving:\n\n");
for(i=0; i<M; i++)
{ for(j=0; j<N; j++) printf("%3d",x[i][j]);
printf("\n\n");
}
fun(x,2);
printf("The array after moving:\n\n");
for(i=0; i<M; i++)
{ for(j=0; j<N; j++) printf("%3d",x[i][j]);
printf("\n\n");
}
}
2、程序修改题 校园网·新视野教育上机考试复习资料
#include <stdio.h>
#include <string.h>
void fun( char t[] )
{
char c;
int i, j;
/**********found***********/
for( i = strlen( t ); i; i-- )
for( j = 0; j < i; j++ )
/**********found***********/
if( t[j] < t[ j + 1 ] )
{
c = t[j];
t[j] = t[ j + 1 ];
t[j + 1 ] = c;
}
}
main()
{
char s[81];
printf( "\nPlease enter a character string: " );
gets( s );
printf( "\n\nBefore sorting:\n \"%s\"", s );
fun( s );
printf( "\nAfter sorting decendingly:\n \"%s\"\n", s );
}
3、程序设计题 校园网·新视野教育上机考试复习资料
#include <stdio.h>
#include <string.h>
void fun( char *ss )
{
}
void main( void )
{
printf( "\nPlease enter an character string within 50 characters:\n" );
gets( tt );
printf( "\n\nAfter changing, the string\n \"%s\"", tt );
fun(tt) ;
printf( "\nbecomes\n \"%s\"", tt );
}
第8套 校园网·新视野教育上机考试复习资料
1、程序填空题
#include <stdio.h>
int fun(int x)
{ int n, s1, s2, s3, t;
n=0;
t=100;
/**********found**********/
while(t<=__1__){
/**********found**********/
s1=t%10; s2=(__2__)%10; s3=t/100;
/**********found**********/
if(s1+s2+s3==__3__)
{ printf("%d ",t);
n++;
}
t++;
}
return n;
}
main()
{ int x=-1;
while(x<0)
{ printf("Please input(x>0): "); scanf("%d",&x); }
printf("\nThe result is: %d\n",fun(x));
}
2、程序修改题 校园网·新视野教育上机考试复习资料
#include <stdio.h>
/************found************/
void fun (long s, long t)
{ long sl=10;
s /= 10;
*t = s % 10;
/************found************/
while ( s < 0)
{ s = s/100;
*t = s%10*sl + *t;
sl = sl * 10;
}
}
main()
{ long s, t;
printf("\nPlease enter s:"); scanf("%ld", &s);
fun(s, &t);
printf("The result is: %ld\n", t);
}
3、程序设计题 校园网·新视野教育上机考试复习资料
#include <stdio.h>
#define N 16
typedef struct
{ char num[10];
int s;
} STREC;
void fun( STREC a[] )
{
STREC tmp;
int i,j;
for(i = 0; i < N; i++)
for(j = i+1; j < N; j++)
{ /* 请按题目要求完成以下代码 */
}
}
main()
{ STREC s[N]={{"GA005",85},{"GA003",76},{"GA002",69},{"GA004",85},
{"GA001",91},{"GA007",72},{"GA008",64},{"GA006",87},
{"GA015",85},{"GA013",91},{"GA012",64},{"GA014",91},
{"GA011",66},{"GA017",64},{"GA018",64},{"GA016",72}};
int i;FILE *out ;
fun( s );
printf("The data after sorted :\n");
for(i=0;i<N; i++)
{ if( (i)%4==0 )printf("\n");
printf("%s %4d ",s[i].num,s[i].s);
}
printf("\n");
out = fopen("\\out.dat","w") ;
for(i=0;i<N; i++)
{ if( (i)%4==0 && i) fprintf(out, "\n");
fprintf(out, "%4d ",s[i].s);
}
fprintf(out,"\n");
fclose(out) ;
}
第9套 校园网·新视野教育上机考试复习资料
1、程序填空题
#include <stdio.h>
#define N 4
fun(int t[][N], int n)
{ int i, sum;
/**********found**********/
___1___;
for(i=0; i<n; i++)
/**********found**********/
sum+=___2___ ;
for(i=0; i<n; i++)
/**********found**********/
sum+= t[i][n-i-___3___] ;
return sum;
}
main()
{ int t[][N]={21,2,13,24,25,16,47,38,29,11,32,54,42,21,3,10},i,j;
printf("\nThe original data:\n");
for(i=0; i<N; i++)
{ for(j=0; j<N; j++) printf("%4d",t[i][j]);
printf("\n");
}
printf("The result is: %d",fun(t,N));
}
2、程序修改题 校园网·新视野教育上机考试复习资料
#include <stdio.h>
#include <math.h>
double funx(double x)
{ return(2*x*x*x-4*x*x+3*x-6); }
double fun( double m, double n)
{
/************found************/
int r;
r=(m+n)/2;
/************found************/
while(fabs(n-m)<0.001)
{ if(funx(r)*funx(n)<0) m=r;
else n=r;
r=(m+n)/2;
}
return r;
}
main( )
{ double m,n, root;
printf("Enter m n : \n"); scanf("%lf%lf",&m,&n);
root=fun( m,n );
printf("root = %6.3f\n",root);
}
3、程序设计题 校园网·新视野教育上机考试复习资料
#include <stdio.h>
void fun( char *a, char *h,char *p )
{
}
main()
{ char s[81],*t, *f;
printf("Enter a string:\n");gets(s);
t=f=s;
while(*t)t++;
t--;
while(*t=='*')t--;
while(*f=='*')f++;
fun( s , f,t );
printf("The string after deleted:\n");puts(s);
}
第10套 校园网·新视野教育上机考试复习资料
1、程序填空题
#include <stdio.h>
/**********found**********/
___1___ fun(char ch)
{
/**********found**********/
if (ch>='0' && ___2___)
/**********found**********/
return '9'- (ch-___3___);
return ch ;
}
main()
{ char c1, c2;
printf("\nThe result :\n");
c1='2'; c2 = fun(c1);
printf("c1=%c c2=%c\n", c1, c2);
c1='8'; c2 = fun(c1);
printf("c1=%c c2=%c\n", c1, c2);
c1='a'; c2 = fun(c1);
printf("c1=%c c2=%c\n", c1, c2);
}
2、程序修改题 校园网·新视野教育上机考试复习资料
#include <stdio.h>
void fun(char *p, char *b)
{ int i, k=0;
while(*p)
{ i=1;
while( i<=3 && *p ) {
/**********found**********/
b[k]=p;
k++; p++; i++;
}
if(*p)
{
/**********found**********/
b[k++]=" ";
}
}
b[k]='\0';
}
main()
{ char a[80],b[80];
printf("Enter a string: "); gets(a);
printf("The original string: "); puts(a);
fun(a,b);
printf("\nThe string after insert space: "); puts(b); printf("\n\n");
}
3、程序设计题 校园网·新视野教育上机考试复习资料
#include <stdio.h>
#include <stdlib.h>
#define N 8
struct slist
{ double s;
struct slist *next;
};
typedef struct slist STREC;
double fun( STREC *h )
{
}
STREC * creat( double *s)
{ STREC *h,*p,*q; int i=0;
h=p=(STREC*)malloc(sizeof(STREC));p->s=0;
while(i<N)
{ q=(STREC*)malloc(sizeof(STREC));
q->s=s[i]; i++; p->next=q; p=q;
}
p->next=0;
return h;
}
outlist( STREC *h)
{ STREC *p;
p=h->next; printf("head");
do
{ printf("->%4.1f",p->s);p=p->next;}
while(p!=0);
printf("\n\n");
}
main()
{ double s[N]={85,76,69,85,91,72,64,87},ave;
STREC *h;
h=creat( s );
展开阅读全文