设为首页 加入收藏

TOP

C语言编程笔试题(第二十套)
2014-11-24 01:23:02 来源: 作者: 【 】 浏览:6
Tags:语言编程 试题 第二十

编程题:


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


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


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


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


#include


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(“\n\n”) ;


}



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


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


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


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


#include


#include


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 :%ld\n”, c);


}



改错题:


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


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


容应为ABCDDCBA。


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


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


试题程序:


#include


#include


#include


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


void fun(char s, char t)


{


int i, d;


d = strlen(s);


for (i = 0; i

t[i] = s[i];


for (i = 0; i

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


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


t[2*d-1] = ‘\0′;


}


main()


{


char s[100], t[100];


clrscr();


printf(“\nPlease enter string S:”);


scanf(“%s”, s);


fun(s,t);


printf(“\nThe result is : %s\n”, t);


}




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


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


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


试题程序:


#include


#include


#include


fun ( int n, int *a )


{


int i, j, p, t;


for ( j = 0; j

{


p=j;


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


for ( i=j+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(“\n\nBefore sorting %d numbers:\n”, n );


putarr( n, aa );


fun( n, aa );


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


putarr( n, aa );


}


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C语言编程笔试题(第十九套) 下一篇C语言编程笔试题(第二十一套)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: