78.请编写函数fun,其功能是:将s所指字符串中ASCII值为偶数的字符删除,串中剩余字符形成一个新串放在t所指的数组中。
例如,若s所指字符串中的内容为ABCDEFGl2345,其中字符B的ASCII码值为偶数、…、字符2的ASCII码值为偶数、…都应当删除,其他依此类推。最后t所指的数组中的内容应是ACEGl35。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若于语句。
#include
#include
#include
void fun( char *s, char t[])
{
}
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);
}
80.程序定义了NxN的二维数组,并在主函数中自动赋值。请编写函数fun(int a[][N],int n),该函数的功能是:使数组左下半三角元素中的值乘以n。例如:若n的值为3,a数组中的值为:,则返回主程序后a数组中的值应为:。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
#include
#include
#include
#define N 5
int fun ( int a[][N]), int n )
{
}
main()
{ int a[N][N], n, i, j;
clrscr();
printf(“***** The array *****\n”);
for ( i=0; i { for(j=0; j {a[i][j]=rand()%10; printf(“%4d”,a[i][j]);} printf(“\n”); } do n = rand()%10 ; while ( n >=3 ); printf(“n = %4d\n”, n); fun ( a, n ); printf(“***** THE RESULT *****\n”); for(i=0;i { for ( j=0; j printf(“\n”); } } 改错题: 5.假定整数数列中的数不重复,并存放在数组中。下列给定程序中,函数fun的功能是:删除数列中值为X的元素,同时将其它元素前移。n中存放的是数列中元素的个数。 请改正程序中的错误,使它能得出正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include #define N 20 fun(int *a,int n,int x) { int p=0,i; a[n]=x; while(x!=a[p]) { p=p+1; } if(p==n) return -1; else { /********found********/ for(i=p;i a[i+1]=a[i]; return n-1; } } main() { int w[N]={-3,0,1,5,7,99,10,15,30,90},x,n,i; n=10; printf(“The original data:\n”); for(i=0;i printf(“\nInput x (to delete):”); scanf(“%d”,&x); printf(“Delete :%d\n”,x); n=fun(w,n,x); if(n==-1) printf(“***Not be found!***\n\n”); else { printf(“The data after delete :\n”); for(i=0;i printf(“%5d”,w[i]); printf(“\n\n”); } } 8.下列给定程序中,函数fun的功能是:在字符串str中找出ASCII码值最大的字符, 将其放在第一个位置上;并将该字符前的原字符向后顺序移动。例如,调用fun函数之前给字符串输入:ABCDeFGH,调用后字符串中的内容为:eABCDFGH。 请修改程序中的错误,使它能计算出正确的结果。 注意:不要改动main函数,不得增行和删行,也不得更改程序的结构! 试题程序: #include /********found********/ fun(char *p) { char max,*q; int i=0; max=p[i]; while(p[i]!=0) { if(max { /********found********/ max=p[i]; p=q+i; } i++; } while(q>p) { *q=*(q-1); q–; } p[0]=max; } main() { char str[80]; printf(“Enter a string: “); gets(str); printf(“\nThe original string: “); puts(str); fun(str); printf(“\nThe string after moving: “); puts(str); printf(“\n\n”); }