更多"请补充函数proc( ),该函数的功能是按条件删除一个字符串指定字符一"的相关试题:
[填空题]请补充函数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( ),该函数的功能是按条件删除一个字符串指定字符一半的数目,具体要求如下:如果该字符串所包含的指定字符的个数是奇数,则不予删除,如果其数目是偶数,则删除原串后半部分的指定字符。其中,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:");
[填空题]请补充fun函数,该函数的功能是:把字符的ASCII码为奇数的字符从字符串str中删除,结果仍然保存在字符串中,字符串str从键盘输入,其长度作为参数传入fun函数。
例如,输入“abcdef”则输出“bdf”。
注意:部分源程序已给出。
请勿改动主函数main和其他函数中的任何内容,仅在main函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#define N 100
void (1)
int i,j;
(2) ;
for(i=0;i<n;i++)
char str[N];
printf("please input a string:/n");
gets(str);
while(str[i]!=’/0’)
len++;
if(s[i]%2==0)
s[j++]=s[i];
(3) ;
main( )
int i=0,len=0;
i++;
fun(str,len);
printf("The result string:/n");
puts(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);
}
[填空题]请补充main函数,该函数的功能是:把字符串str中的字符向前移动一位,原来的第一个字符移动到字符串尾,结果仍然保存在原字符串中。
例如,输入“how do you do”,则结果输出“ow do you doh”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include <stdio. h>
#define N 80
main( )
{
char str[N], ch;
int i;
clrscr ( );
printf("/n Input a string:In");
gets (str);
printf("/n*** original string ***In");
puts (str);
ch=str [0];
for (i=0; 【1】 ; i++)
str [i]=str [i+1];
【2】 ;
printf("/n *** new string ***/n");
puts (str);
}
[填空题]请补充main函数,该函数的功能是:把字符串str1中的非空格字符拷贝到字符串str2中。
例如,若sffl=“glad to see you!”,
则str2=“gladtoseeyou!”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#define N 80
main( )
{
static char strl [N] ="glad to see you!";
char str2 IN];
int i=0, j=0;
clrscr ( );
printf("/n***** strl*****/n ");
puts (str1);
while (str1 [i] )
{
if(【1】)
str2 [J++] =strl [i];
【2】;
}
printf("/n***** str2 *****/n ");
for (i=0; i<j; i++)
printf ("%c", str2 [i] );
}
[填空题]请补充函数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);
[多项选择]填空题
请补充main函数,该函数的功能是:从键盘输入一个字符串并保存在字符str1中,把字符串str1中下标为偶数的字符保存在字符串str2中并输出。例如,当str1=“cdefghij”,则str2=“cegi”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include
#include
#define LEN 80
main( )
{
char str1[LEN],str2[LEN];
char *p1=str1,*p2=str2;
int i=0,j=0;
clrscr( );
printf("Enter the string:/n");
scanf(【1】);
printf("***the origial string***/n");
while(*(p1+j))
{
printf("【2】",*(p1+j));
j++;
}
for(i=0;i
[填空题]请补充函数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);