更多"请补充函数fun( ),该函数的功能是按条件删除一个字符串指定字符一半"的相关试题:
[填空题]请补充函数fun( ),该函数的功能是按条件删除一个字符串指定字符一半的数目,具体要求如下:如果该字符串所包含的指定字符的个数是奇数,则不予删除,如果其数目是偶数,则删除原串后半部分的指定字符。其中,a指向原字符串,删除后的字符串存放在b所指的数组中,c中存放指定的字符。
例如:当a输入“abababa”,c=‘a’时,b的输出为“ababb”;
如果a的输入为“ababa”,则b的输出为“ababa”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<conio.h>
#define LEN 80
void fun(char a[],char b[],char C)
{
int i=0,j=0;
int n=0;
int m=0;
while(a[i]!=‘/0’)
{
if(a[i]==c)
n++;
i++;
}
【1】 ;
if(n%2)
{
while(a[j]!=’/0’)
{
b[j]=a[j];
j++;
}
b[j]=’/0’;
}
else
{
while(a[i]!=’/0’)
{
b[j++]=a[i];
if(a[i]==c)
m++;
if((m>n/2)&&(a[i]==c))
【2】 ;
i++;
}
【3】 ;
}
}
main( )
{
char a[LEN],b[LEN];
char c;
clrscr( );
printf("Enter the string:/n");
gets(a);
printf("Enter the character of the string deleted:");
[填空题]请补充函数proc( ),该函数的功能是按条件删除一个字符串指定字符一半的数目,具体要求如下:如果该字符串所包含的指定字符的个数是奇数,则不删除,如果其数目是偶数,则删除原串后半部分的指定字符。其中,str指向原字符串,删除后的字符串存放在b所指的数组中,e中存放指定的字符。例如,当str输入“abcabcabcab”,c=“b”时,b的输出为“abcabcaca”;如果str的输入为“abcabeabca”,则b的输出为“abcabcabca”。
注意:部分源程序已给出。
请勿改动主函数main和其他函数中的任何内容。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#define M 80
void proc(char str[], char b[], char c)
int i=0, j=0;
int n=0;
int m=0;
while(str[i]!=’/0’)
if(str[i]==c)
n++;
i++;
(1) ;
if (n%2)
while(str[j]!=’/0’)
b[j]=str[j];
j++;
b[j]=’/0’;
else
while(str[i]!=’/0’)
b[j++]=str[i];
if(str[i]==c)
m++;
if((m>n/2)&&(str[i]==c))
(2) ;
i++;
(3) ;
void main( )
char str[M], b[M];
char c;
system("CLS");
printf("Enter the string: /n");
gets(str);
[填空题]请补充函数fun( ),该函数的功能是:把字符下标为非素数的字符从字符串sb中删除,把字符下标为素数的字符重新保存在字符串e口中。字符串sb从键盘输入,其长度作为参数传入函数fun( )。
例如,输入“abcdefghijkl”,输出“cdfhl”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
试题程序:
#include <stdio.h>
#define N 80
void fun(char s[],int n)
{
int i, j, k, flag;
【1】 ;
for(i=0; i<n; i++)
{
if (i>1)
s [k++] =s [i];
flag=I;
for( 【2】 ; j<i&&flag; j++)
if (i%j==0)
{
flag=0;
【3】
}
}
s [k]=’/0’;
}
main( )
{
int i=0, strlen=0;
char str[N];
clrscr ( );
printf("/n Input a string:/n");
gets (str);
while (str [i] !=’/0’)
{
strlen++;
i++;
}
fun (str, strlen);
printf("/n*** display string ***/n");
puts (str);
}
[填空题]请补充函数fun( ),该函数的功能是:把字符下标能铍2或3整除的字符从字符串str中删除,把剩余的字符重新保存在字符串str中。字符串str从键盘输入,其长度作为参数传入函数fun( )。
例如,输入“abcdefghijk”,输出“bfh”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include <stdio.h>
#define N 80
void fun(char s[], int n)
int i, k;
【1】 ;
for(i=0; i<n; i++)
s[k++]=s[i];
if( 【2】 )
k--;
【3】 ;
main( )
int i=0,strlen=0;
char str[N];
clrscr( );
printf("/nInput a string:/n");
gets(str);
while(str[i]!=’/0’)
strlen++;
i++;
fun(str,strlen);
printf(’/n*** display string ***/n");
puts(str);
[简答题]编写函数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);
[填空题]请补充函数fun( ),该函数的功能是:把ASCII码为奇数的字符从字符串str中删除,结果仍然保存在字符串str中。字符串str从键盘输入,其长度作为参数传入函数fun( )。
例如,输入“abcdef”,输出“bdf”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include <stdio.h>
#define N 80
void fun(char s[],int n)
{
int i, j;
j=0;
for(i=0; 【1】 ;i++)
{
if( 【2】 )
s [j++]-s [i];
}
【3】 ;
}
main ( )
{
int i=0, strlen=0;
char str [N];
clrscr ( );
printf ("/nInput a string: /n");
gets (str);
while (str [i] !=’/0’)
{
strlen++;
i++;
}
fun(str, strlen);
printf("/n*** display string ***/n");
puts (str);
}
[简答题]请编写函数fun( ),该函数的功能是:将s所指字符串中 ASCII值为偶数的字符删除,串中剩余字符形成一个新串放在t所指的数组中。
例如,若s所指字符串中的内容为ABCDEFGl2345,其中字符B的ASCⅡ码值为偶数、…、字符2的ASCⅡ码值为偶数、…,都应当删除,其他依次类推。最后t所指的数组中的内容应是ACEGl35。
注定:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序;
#include <stdio. h>
#include<string.h>
#include<conio. h>
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);
}
[填空题]请补充函数fun( ),该函数的功能是:把ASCⅡ码为偶数的字符从字符串s打中删除,结果仍然保存在字符串srt中,字符串str从键盘输入,其长度作为参数传入函数fun( )。
例如,输入“abcdef”,输出“ace”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#inc lude< stdio, h>
#define N 80
【1】
{
int i, j;
【2】
for (i=0;i<n;i++)
{
if (s [i] %2!=0)
s [j++]=s [i];
}
【3】 ;
}
main ( )
{
int i=0, strlen=0;
char str[N];
clrscr ( );
printf ("/nInput a string:/n");
gets (str);
while (str [i] !=’ /0’ )
{
strlen++;
i++;
}
fun (str, strlen);
printf("/n*** display string ***/n");
puts (str);
}
[简答题]编写函数fun( ),该函数的功能是从字符串中删除指定的字符,同一字母的大、小写按不同字符处理。
例如:程序执行时输入字符串为turbo c and borland c++,从键盘上输入字符n,则输出后变为turbo c ad borlad c++。
如果输入的字符在字符串中不存在,则字符串照原样输出。
注意:部分源程序已存在文件test18_2.cpp中。
请勿改动主函数脚in和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
文件test18_2.cpp的内容如下:
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
void fun(char s[ ], int c)
{
}
void main ( )
{
static char str[ ]="turbo c and borland c++";
char ch;
cout<<"原始字符串:/n"<<str<<end1;
cout<<"输入一个字符:";
cin>>ch;
fun(str.ch);
cout<<"str="<<str<<end1;
}