问答题
编写函数fun,其功能是:删除一个字符串中指定下标的字符。其中,a指向原字符串,删除指定字符后的字符串存放在b所指的数组中,n放指定的下标。
例如,输入一个字符串“world”,然后输入3,则调用该函数后的结果为“word”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#define LEN 20
void fun(char a[],har b[],int n)
void main()
char strl[LEN],str2[LEN];
int n;
system("CLS");
printf("Enter the string:\n");
gets(str1);
printf("Enter the position of the string deleted:");
scanf("%d",&n);
fun[str1,str2,n);
printf("The new string is:%s\n",str2);
【参考答案】
void fun(char a[]char b[],int n)
{
int i,k=0;
(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)
点击查看答案&解析
<上一题
目录
下一题>
热门
试题
问答题
下列给定程序中,函数fun的功能是:用下面的公式求π的近似值,直到最后一项的绝对值小于指定的数(参数num)为止。 例如,程序运行后,输入0.0001,则程序输出3.1414。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序: #include<stdlib.h> #include<math.h> #include<sfdio.h> float fun(float num) int s; float n,t,pi; f=1;pi=0;n=1;s=1; *******found******** while(t>=num) pi=pi+t; n=n+2; s=-s; ********found******** t=s%n; pi=pi*4; return pi; void main() float n1,n2; system( CLS ); printf( Enter a float number: ); scanf( %f&n1); n2=fun(n1); printf( %6.4f n ,n2);
点击查看答案&解析
问答题
下列给定程序中,函数fun的功能是:将形参s所指字符串中下标为奇数的字符取出,并按ASCⅡ码大小递增排序,将排序后的字符存入形参P所指的字符数组中,形成一个新串。 例如,形参s所指的字符串为“baawrskjghzlicda”,执行后P所指字符数组中的字符串应为“aachjlsw”。 请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #include<stdio.h> void fun(char*s,char*p) int i,j,n,x,t; n=0; for(i=0;s[i]!=’ 0’;i++)n++; for(i=l;i ********fOund******** (1) ; ********found******** for(j= (2) +2;j<n;j=j+2) if(s[t]>s[j])t=j; if(t!=i) (x=s[i];s[i]=s[t];s[t]=x;) for(i=1,j=0;i<n;i=i+2,j++) p[j]=s[i]; ********found******** p[j]= (3) ; ( char s[80]= baawrskjghzlicda ,p[50]; printf( nThe original string is:%s n ,s); fun(s,p); printf( nThe result is:%s n ,p);
点击查看答案&解析
相关试题
下列给定程序中,函数fun的功能是:用下面...
下列给定程序中,函数fun的功能是:将形参s...