C二级第四套试题

1.

题目

代码

#include  <stdlib.h>
#include  <stdio.h>
#define   N   10//宏定义
double fun(double  *x)
{ int  i, j;    double  s, av, y[N];
  s=0;
  for(i=0; i<N; i++)  s=s+x[i];
/**********found**********/
  av=s/N;//平均值
  for(i=j=0; i<N; i++)
    if( x[i]>av ){//大于av的存在它的前面.临时数组y[j++]
/**********found**********/
      y[j++]=x[i];
	  x[i]=-1;}
  for(i=0; i<N; i++)
/**********found**********/
    if( x[i]!= -1) y[j++]=x[i];//小与平均值的数
  for(i=0; i<N; i++)x[i] = y[i];//将y中的元素全部分配给x
  return  av;
}
void main()
{ int  i;     double  x[N];
  for(i=0; i<N; i++){ x[i]=rand()%50; printf("%4.0f ",x[i]);}//自动生成0~49的数
  printf("\n");//打印输出
  printf("\nThe average is: %f\n",fun(x));//打印输出平均值
  printf("\nThe result :\n",fun(x));//打印输出结果
  for(i=0; i<N; i++)  printf("%5.0f ",x[i]);//打印输出移动后的数据
  printf("\n");
}

结果

2.

题目

代码

#include  <stdlib.h>
#include  <string.h>
#include  <conio.h>
#include  <ctype.h>
#include  <stdio.h>
#include  <string.h>
/*************found**************/
void upfst(char *p)//指针类型
{
  int k=0;
  for ( ;*p;p++)
     if (k)
        {
         if (*p==' ') //文本第一个单词为空 
         	k=0;
        }
     else
        {
			if (*p!=' ')  //文本第一个单词不为空,说明找到单词
			{
				k=1;
				*p=toupper(*p);//单词第一个字母转化成大写
			}
		}
}
void main()
{
	char  chrstr[81];//定义了一个数组
	system("CLS");    
	printf("\nPlease enter an English text line: ");
	gets(chrstr);
	printf("\nBofore changing:\n  %s",chrstr);
	upfst(chrstr);
	printf("\nAfter changing:\n  %s\n",chrstr);
}

结果

3.

题目

代码

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define  N  5
double fun (int w[][N])
{ 
	int i,j,count=0;
	double s=0.0;
	for(i=0;i<N;i++){
		for(j=0;j<N;j++){
			if(i==0||j==0||i==N-1||j==N-1){
				s+=w[i][j];
				count++;
			}
		}
		
	}
	
	return s/count;
}
void main()
{
  FILE *wf;
  int a[N][N]={0,1,2,7,9,1,9,7,4,5,2,3,8,3,1,4,5,6,8,2,5,9,1,4,1};//定义了一个数组
  int i, j;
  double s;
  system("CLS");
  printf("*****The array*****\n ");//输出数组
  for (i=0; i<N; i++)
    { for (j=0;j<N;j++)
         {printf("%4d ",a[i][j]);}
      printf("\n ");
    }
  s=fun(a);//求四周的平均值
  printf("*****THE RESULT*****\n ");
  printf("The sum is : %lf\n ",s);
/******************************/
  wf=fopen("out.dat","w");
  fprintf (wf,"%lf",s);
  fclose(wf);
/*****************************/
}

结果

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值