C–Question
这里留言就可以了我每天都看
上机部分
一、填空题
请补充函数fun( ),该函数的功能是:依次取出字符串中所有的小写字母以形成新的字符串,并取代原字符串。注意:部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
void fun(char *s)
{
int i=0;
char *p=s;
while (【1】)
{
if ( *p>=’a’ && *p<=’z')
{
s=*p;
【2】;
}
p++;
}
s=【3】;
}
void main( )
{
char str[80];
system(”CLS”);
printf(”\nEnter a string:”);
gets(str);
printf(”\n\nThe string is: %s\n”,str);
fun(str);
printf(”\n\nThe string of changing is : %s\n”,str);
}
二、改错题
下列给定程序中,函数fun()功能是:将m(1<=m<=10)个字符串反着连接起来,组成一个新串,放入pt所指字符串中,例如:把3个串DEG,ac,df反着串联起来,结果是dfacDEG。请改正程序中的错误,使它能得出正确的结果。注意:不要改动main( )函数,不得增加或者删行,也不得改变程序的结构。
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>
void fun (char str[ ][10], int m, char *pt)
{
int k,q,i,j=0;
/**********found**********/
for(k=m;k>0;k–)
{
q=strlen(str[k]);
j+=q;
for(i=0;i<q;i++)
pt=str[k];
pt+=q;
pt[0]=0;
}
/***********found********/
pt=j;
}
void main( )
{
int m,h;
char s[10][10],p[120];
system(”cls”);
printf(”\n please enter m:”);
scanf(”%d”,&m);
printf(”\n please enter %d string:\n”,m);
gets(s[0]);
for(h=0;h<m;h++)
gets(s[h]);
fun(s,m,p);
printf(”\n the result is :%s\n”,p);
}
三、编程题
下列程序定义了N*N的二维数组,并在主函数中自动赋值。请编写函数fun(int a[ ][N], int n),该函数的功能是:使数字右上半三角元素中的值乘以m。
例如,若m的值为2,a数组中的值为:
A=1
9
2 7
则返回主程序后a数组的值应为:
2 18
2 14
注意:部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#define
N
5
void fun(int a[ ][N], int m)
{
}
void main()
{
int a[N][N],m,i,j;
system(”CLS”);
printf(”******the
array ******\n”);
for(i=0;i<N;i++)
/*输出一个随机的5*5矩阵*/
{ for(j=0;j<N;j++)
{ a[j]=rand( )%20;
printf(”%d”,a[j]);
}
printf(”\n”);
}
do
m=rand( )%10;
while(m>=3);
/*产生一个小于3的随机数*/
printf(”m=%4d\n”,m);
fun(a,m);
printf(”THE
RESULT\n”);
for(i=0;i<N;i++)
{ for(j=0;j<N;j++)
printf(”%4d”,a[j]);
printf(”\n”);
}
}
音频片段:需要 Adobe Flash Player(9 或以上版本)播放音频片段。 点击这里下载最新版本。您需要开启浏览器的 JavaScript 支持。
音频片段:需要 Adobe Flash Player(9 或以上版本)播放音频片段。 点击这里下载最新版本。您需要开启浏览器的 JavaScript 支持。

Leave a Reply