第6题 (10.0分) 题号:151 难度:中 第8章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:请编写函数fun,该函数的功能是:将M行N列的二维数组中的字符数据,按列的顺序依
次放到一个字符串中。
例如:若二维数组中的数据为
W W W W
S S S S
H H H H
则字符串中的内容应是: WSHWSHWSHWSH。
注意:请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入
所编写的若干语句。
-------------------------------------------------------*/
#include
#define M 3
#define N 4
void fun(char (*s)[N],char *b)
{
/**********Program**********/
/********** End **********/
}
void main()
{
char a[100];
char w[M][N]={{ 'W', 'W', 'W', 'W'},{'S', 'S', 'S', 'S'},
{'H', 'H', 'H', 'H'}};
int i,j;
printf("The matrix:\n");
for(i=0;i
{
for(j=0;j
printf("%3c",w[i][j]);
printf("\n");
}
fun(w,a);
printf("The A string:\n");
puts(a);
printf("\n\n");
}
第7题 (10.0分) 题号:137 难度:中 第8章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:请编写函数fun,其功能是:统计s所指字符串中的数字字符个数,并作为函数值
返回。
例如:s所指字符串中的内容是:2def35adh25 3kjsdf 7/kj8655x,函数fun返回值为:11
注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入
你编写的若干语句。
-------------------------------------------------------*/
#include
int fun(char *s)
{
/**********Program**********/
/********** End **********/
}
void main()
{
char *s="2def35adh25 3kjsdf 7/kj8655x";
printf("%s\n",s);
printf("%d\n",fun(s));
}
第8题 (10.0分) 题号:116 难度:中 第8章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:编写函数fun,其功能是:将s所指字符串中ASCII值为奇数的字符删除,剩余字符形
成的新串放在t所指数组中。
例如:若s所指字符串中的内容为:"ABCDEFG12345",其中字符A的ASCII码值为奇数,字符1
的ASCII码值也为奇数,都应当删除,其它依此类推。最后t所指的数组中的内容应
是:"BDF24"。
注意:请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入
你编写的若干语句。
-------------------------------------------------------*/
#include
#include
void fun(char *s, char t[])
{
/**********Program**********/
/********** End **********/
}
void main()
{
char s[100], t[100];
printf("\nPlease enter string S:");
scanf("%s", s);
fun(s, t);
printf("\nThe result is: %s\n", t);
}
第9题 (10.0分) 题号:159 难度:中 第8章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:编写函数fun,w是一个大于10的无符号整数,若w是n(n≥2)位的整数,则函数求
出w的后n-1位的数作为函数值返回。
例如:w值为5923,则函数返回923;若w值为923,则函数返回23。
注意:请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入
你编写的若干语句。
-------------------------------------------------------*/
#include
#include
#include
unsigned fun(unsigned w)
{
/**********Program**********/
/********** End **********/
}
void main()
{
unsigned x;
printf("Enter a unsigned integer number: ");
scanf ("%u",&x);
printf("The original data is:%u\n",x);
if(x<10)
printf("Data error! ");
else
printf ("The result :%u\n", fun(x));
}
第10题 (10.0分) 题号:128 难度:中 第8章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:函数fun的功能是:将两个两位数的正整数 a、b合并成一个整数放在c中。
合并的方式是:将a数的十位和个位数依次放在c数的千位和十位上,b数的
十位和个位数依次放在c数的百位和个位上。
例如:当a=45,b=12时,调用该函数后c=4152。
注意:请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入
你编写的若干语句。
-------------------------------------------------------*/
#include
void fun(int a, int b, long *c)
{
/**********Program**********/
/********** End **********/
}
void main()
{
int a,b; long c;
printf("Input a, b:");
scanf("%d %d", &a, &b);
fun(a, b, &c);
printf("The result is: %d\n", c);
}