C语言编程笔试题(第二十套)

匿名网友 匿名网友 发布于: 2015-08-30 00:00:00
阅读 109 收藏 0 点赞 0 评论 0

编程题:

75.请编写函数fun,该函数的功能是:将M行N列的二维数组中的数据,按列的顺序依次放到一维数组中。

例如,若二维数组中的数据为:,则一维数组中的内容应是:33  44  55  33  44  55  33  44  55  33  44  55。

注意:部分源程序给出如下。

请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

#include <stdio.h>

void fun(int  (*s)[10], int *b, int *n, int mm, int nn)

{

}

main()

{

int w[10][10] = {{33,33,33,33},{44,44,44,44},{55,55,55,55}}, i, j ;

int a[100] = {0}, n = 0 ;

printf(“The matrix:n”) ;

for(i = 0 ; i < 3 ; i++)

{

for(j = 0 ; j < 4 ; j++)

printf(“%3d”,w[i][j]) ;

printf(“n”) ;

}

fun(w, a, &n, 3, 4) ;

printf(“The A array:n”) ;

for(i = 0 ; i < n ; i++)

printf(“%3d”,a[i]);

printf(“nn”) ;

}

 

77.请编写函数fun,其功能是:将两个两位数的正整数a、b合并形成一个整数放在c中。合并的方式是:将a数的十位和个位数依次放在c数的个位和百位上,b数的十位和个位数依次放在c数的十位和千位上。

例如,当a=45,b=12,调用该函数后,c=2514。

注意:部分源程序给出如下。

请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

#include <conio.h>

#include <stdio.h>

void fun(int a,int b , long *c)

{

}

 

main()

{

int a,b;

long c;

clrscr();

printf(“Input a, b:”);

scanf(“%d%d”,&a, &b);

fun(a, b, &c);

printf(“The result is :%ldn”, c);

}

 

改错题:

39.下列给定程序中,函数fun的功能是:将s所指字符串的正序和反序进行连接,形

成一个新串放在t所指的数组中。例如,当S所指字符串为ABCD时,则t所指字符串中的内

容应为ABCDDCBA。

请改正程序中的错误,使它能得出正确的结果。

注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!

试题程序:

#include <conio.h>

#include <stdio.h>

#include <string.h>

/********found********/

void fun(char  s, char  t)

{

int  i, d;

d = strlen(s);

for (i = 0; i<d; i++)

t[i] = s[i];

for (i = 0; i<d; i++)

t[d+i] = s[d-1-i];

/********found********/

t[2*d-1] = ‘’;

}

main()

{

char  s[100], t[100];

clrscr();

printf(“nPlease enter string S:”);

scanf(“%s”, s);

fun(s,t);

printf(“nThe result is : %sn”, t);

}

 

 

40.下列给定程序中fun函数的功能是:将n个无序整数从小到大排序。

请改正程序中的错误,使它能得出正确的结果。

注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!

试题程序:

#include <conio.h>

#include <stdio.h>

#include <stdlib.h>

fun ( int  n, int *a )

{

int  i, j, p, t;

for ( j = 0; j<n-1 ; j++ )

{

p=j;

/********found********/

for ( i=j+1; i<n-1 ; i++ )

if ( a[p]>a[i] )

/********found********/

t=i;

if ( p!=j )

{

t = a[j];

a[j] = a[p];

a[p] = t;

}

}

}

 

putarr( int  n, int  *z )

{

int  i;

for ( i = 1; i <= n; i++, z++ )

{

printf(“%4d”, *z );

if ( !(i%10 ) )

printf( “n” );

}

printf(“n”);

}

main()

{

int  aa[20]={9,3,0,4,1,2,5,6,8,10,7}, n=11;

clrscr();

printf(“nnBefore sorting %d numbers:n”, n );

putarr( n, aa );

fun( n, aa );

printf( “nAfter sorting %d numbers:n”, n );

putarr( n, aa );

}

评论列表
文章目录