编程题:
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] = ‘