全国二级C语言11~20套试题汇编——————编程练习题

第十一套:

11.1:计算数学公式

double f1(double  x)
{  return  x*x;  }
double f2(double x, double y)
{  return  x*y;  }
double fun(double  a, double  b)
{
/**********found**********/
  double (*f)();
  double  r1, r2;
/**********found**********/
  f =  f1; 
  r1 = f(a);
/**********found**********/
  f = f2 ; 
  r2 = (*f)(a, b);
  return  r1 + r2;
}

11.2:累加单链表中的偶数值

typedef struct aa
{ int data;
  struct aa *next;
} NODE;
int fun (NODE *h)
{ int sum=0;
  NODE *p;
  p=h->next;
/*************found**************/
  while(p!=NULL)
       { if(p->data%2==0)
             sum+=p->data;
/*************found**************/
          p=p->next;
       }
  return sum;
}

11.3:—回文数—

int fun(char *str)
{
	int i,n=0,flag=1;
	char *p;
	p=str;
	while(*p)
	{
		p++;
		n++;
	}
	for(i=0;i<n/2;i++)
		if(str[i]==str[n-i-1]);
		else
		{
			flag=0;
			break;
		}
		return flag;
}

第十二套:

12.1:顺序遍历单链表

typedef struct node {
  int  data;
  struct node  *next;
} NODE;
void fun(NODE  *h)
{ NODE  *p, *q;    int  t;
/**********found**********/
  p = h->next ;
  while (p) {
/**********found**********/
     q = p->next  ;
     while (q) {
/**********found**********/
        if (p->data > q->data)
        {  t = p->data;  p->data = q->data;  q->data = t;  }
        q = q->next;
    }
    p = p->next;
  }
}

12.2:找出单链表中的最大值

typedef struct aa
{ int data;
  struct aa *next;
} NODE;
int fun (NODE *h)
{ int max=-1;
  NODE *p;
/*************found**************/
  p=h->next;
  while(p)
       { if(p->data>max)
             max=p->data;
/*************found**************/
          p=p->next;
       }
  return max;
}

12.3:按行存储二维数组

void fun (int (*s)[10], int *b, int *n, int mm, int nn)
{
	int i,j,k=0;
	for(i=0;i<mm;i++)
		for(j=0;j<nn;j++)
			b[k++]=s[i][j];
	*n=k;
}

第十三套:

13.1:前移数字字符

char *fun(char  *s)
{ int  i, j, k, n;    char  *p, *t;
  n=strlen(s)+1;
  t=(char*)malloc(n*sizeof(char));
  p=(char*)malloc(n*sizeof(char));
  j=0; k=0;
  for(i=0; i<n; i++)
  {  if(isdigit(s[i])) {
/**********found**********/
       p[j]=s[i]; j++;}
     else
     {  t[k]=s[i]; k++; }
   }
/**********found**********/
   for(i=0; i<k; i++) p[j+i]= t[i];
   p[j+k]=0;
/**********found**********/
   return p;
}

13.2:交叉合并字符与数字

void fun( char  *a, char  *b, char  *c )
{
  int   i , j;     char   ch;
  i = 0;    j = strlen(b)-1;
/************found************/
  while ( i < j )
  {   ch = b[i]; b[i] = b[j]; b[j] = ch;
      i++;    j--;
  }
  while ( *a || *b ) {
/************found************/
     if ( *a )
       { *c = *a;  c++; a++; }
     if ( *b )
       { *c = *b;  c++; b++; }
  }
  *c = 0;
}

13.3:删除字符串中下标为偶数,字符值为奇数的数

void fun(char  *s, char  t[])
{
	int i,j=0;
	for(i=0;s[i]!='\0';i++)
		if(!((i%2==0)&&(s[i]%2)))
			t[j++]=s[i];
	t[j]='\0';
}

第十四套:

14.1:矩阵行交换

void fun(int (*a)[N], int k)
{
  int i,temp ;
/**********found**********/
  for(i = 0 ; i < N ; i++)
  { temp=a[0][i] ;
/**********found**********/
    a[0][i] = a[k][i] ;
    a[k][i] = temp ;
  }
}

14.2:字符按值升序排序

void fun(char  t[])
{
 char c;
 int i,j;
 /*************found**************/
 for(i=strlen(t)-1;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;
          }
}

14.3:将字符串中位置为奇数的字符大写

void fun(char *ss)
{
	int i;
	for(i=0;ss[i]!='\0';i++)
		if((i%2)&&(ss[i]>='a')&&(ss[i]<='z'))
			ss[i]-=32;
}

第十五套:

15.1:矩阵列转移

void fun(int  (*a)[N],int  k)
{
  int  i,j,p,temp;
/**********found**********/
  for(p=1; p<= k; p++)
     for(i=0; i<M; i++)
     {  temp=a[i][0];
/**********found**********/
        for(j=0; j< N -1; j++) a[i][j]=a[i][j+1];
/**********found**********/
        a[i][N-1]= temp;
     }
}

15.2:规格矩阵

void fun(int a[][M], int m)
{
   int j, k ;
   for (j = 0 ; j < m ; j++ )
        for (k = 0 ; k < m ; k++ )
/**************found**************/
          a[j][k] = (k+1) * (j+1) ;
}

15.3:合并新整数

void fun(int  a, int  b, long  *c)
{
*c=(a%10)*1000+(b%10)*100+(a/10)*10+b/10;
}

第十六套:

16.1:找出行-MAX&&列-min的元素

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= j ; }
     find=1; k=0;
     while(k<M && find) {
/**********found**********/
       if (k!=i && a[k][c]<=rmax)  find= 0 ;
       k++;
     }
     if(find) printf("find: a[%d][%d]=%d\n",i,c,a[i][c]);
/**********found**********/
      i++ ;
  }
  if(!find) printf("not found!\n");
}

16.2:计算数学公式

double fun ( int m )
{  
   double   y = 1.0 ;
   int  i ;
/**************found**************/
   for(i = 2 ; i <= m ; i++)
/**************found**************/
      y -= 1.0 /(i * i) ;
   return( y ) ;
}

16.3:分离出低于平均分的成绩

int fun(int score[],int m, int below[])
{
int i,k=0;
double av=0.0;
for(i=0;i<m;i++)
	av+=score[i]/m;
for(i=0;i<m;i++)
	if(score[i]<av)
		below[k++]=score[i];
return k;
                                                         
}

第十七套:

17.1:选择性保留字符串中的字符(逆序)

void fun(char  *s, int  n, char  *t)
{ int len,i,j=0;
  len=strlen(s);
/**********found**********/
  if(n>=len) strcpy(t,s);
  else {
/**********found**********/
     for(i=len-n; i<=len-1; i++)  t[j++]= s[i] ;
/**********found**********/
     t[j]= '\0' ;
  }
}

17.2:找出大于m且最接近m的素数

int fun( int m)
{ 
  int i,k;
  for (i=m+1; ;i++)
     { for (k=2;k<i;k++)
/*************found**************/
          if (i%k==0)
          break;
/*************found**************/
        if (k==i)
        return(i);
     }
}

17.3:找出能整除x且不是偶数的整数(升序)

void fun (int x, int pp[], int *n)
{
	int i,k=0;
	for(i=1;i<x;i++)
		if((i%2)&&(x%i==0))
			pp[k++]=i;
  *n=k;
}

第十八套:

18.1:回文数2.0

int fun(char  *s)
{
 char  *lp,*rp;
/**********found**********/
  lp= s ;
  rp=s+strlen(s)-1;
  while((toupper(*lp)==toupper(*rp)) && (lp<rp) ) {
/**********found**********/
     lp++; rp -- ; }
/**********found**********/
  if(lp<rp) return 0 ;
  else   return 1;
}

18.2:计算数学公式

double fun (int n)
{
  int a,b,c, k;
  double s;
  s=0.0;a=2;b=1;
  for(k=1;k<=n;k++)
     {
/*************found**************/
      s=s+(double)a/b;
      c=a;a=a+b;b=c;
     }
  return s;
}

18.3:—找出大于整数m且紧靠m的k个素数—

void fun(int m,int k,int xx[])
{
	int i,j,n;
	for(i=m+1,n=0;n<k;i++)
	{
		for(j=2;j<i;j++)
			if(i%j==0)
				break;
			if(i==j)
				xx[n++]=i;
	}

第十九套:

19.1:统计行式单词的个数2.0

int fun(char  *s)
{
 int  n=0, flag=0;
  while(*s!='\0')
  { if(*s!=' ' && flag==0) {
/**********found**********/
     n++ ;  flag=1;}
/**********found**********/
    if (*s==' ')  flag= 0 ;
/**********found**********/
    s++ ;
  }
  return  n;
}

19.2:统计低于平均分的人数

int fun(float *s, int n,float *aver)
{ 
  float ave ,t=0.0;
  int count=0,k,i;
  for(k=0;k<n;k++)
/*************found**************/
      t+=s[k];
  ave=t/n;
  for(i=0;i<n;i++)
      if(s[i]<ave) count++;
/*************found**************/
  *aver=ave;
  return count;
}

19.3:—找出数组中的最大元素—

int fun(int *s,int t,int *k)
{
	int i;
	*k=0;
	for(i=0;i<t;i++)
		if(s[*k]<s[i])
			*k=i;
	return s[*k];
}

第二十套:

20.1:存入小于特定值的字符

int fun(char  *s, char  *t)
{
  int  n=0;
  while(*s)
  { if(*s < 97) {
/**********found**********/
     *(t+n)= *s ;  n++;  }
/**********found**********/
     s++ ;
  }
  *(t+n)=0;
/**********found**********/
  return  n ;
}

20.2:—统计平均值以上的数—

int fun(float x[], int n)
/************found************/
{int j, c=0; float xa=0.0;//{--->特别注意!!!
   for (j=0; j<n; j++)
     xa += x[j]/n;
   printf("ave =%f\n",xa);
   for (j=0; j<n; j++)
/************found************/
     if (x[j] >= xa)
       c++;
   return c;
}

20.3:计算数学公式

float  fun(int m, int n)
{
	int i;
	float a=1.0,b=1.0,c=1.0;
	for(i=1;i<=m;i++)
		a*=i;
	for(i=1;i<=n;i++)
		b*=i;
	for(i=1;i<=m-n;i++)
		c*=i;
	return  a/(b*c);
}
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值