更多"函数my_cmp( )的功能是比较字符串s和t的大小,当s等于t时返回"的相关试题:
[填空题]函数my_cmp( )的功能是比较字符串s和t的大小,当s等于t时返回0,否则返回s和t的第一个不同字符的ASCII码差值,即s>t时返回正值,当s<t时返回负值。请填空。
my_cmp(char *s,char*t)
while(*s==*t)
if(*s==’/0’)return 0;
++s; ++t;
return______;
[填空题]函数mycmp(char*s,char*t)的功能提比较字符串s和t的大小,当s等于t时返回0,当s>t返回正值,当s<t时返回负值。请填空。
mycmp(char*s,char*t)
while(*s==*t)
if(*s==’/0’)return0;
++s;++t;
return( 【14】 )
[填空题]请补充函数proc( ),该函数的功能是比较字符串str1和str2的大小,并返回比较的结果。
例如,当str1="abcd",str2="abcc"时,函数proc( )返回“>”,比较结果为“str1>str2”。
注意:部分源程序给出如下。
请勿改动main( )函数和其他函数中的任何内容,仅在函数proc( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#define M 80
char*proc(char*str1,char*str2)
{
char*p1=str1,*p2=str2;
while(*p1&&*p2)
{
if(______)
return"<";
if(______)
return">";
p1++;
p2++;
}
if("p1==*p2)
return"==";
if(*p1==______)
return"<";
else
return">";
}
void main( )
{
char str1[M],str2[M];
system("CLS");
printf("Input str1:/n");
gets(str1);
printf("Input str2:/n");
gets(str2);
printf("/n****the result****/n");
printf("/nstr1%s str2",proc(str1,str2));
}
[填空题]请补充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);
[简答题]编写函数int fun(int lim, int aa[MAX]),该函数的功能是求出小于或等于lim的所有素数并放在aa数组中,该函数返回所求出的素数的个数。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include<conio.h>
#include<stdio.h>
#define MAX 100
int fun(int lim, int se[MAX])
main( )
int limit,i,sum;
int aa[MAX];
clrscr( );
printf("输入一个整数");
scanf("%d",&limit);
sum=fun(limit,aa);
for(i=0;i<sum;i++)
if(i%10==0&&i!=0) /*每行输出10个数*/
printf("/n");
printf("%5d ",aa[i]);
[简答题]编写类AA的成员函数int Compare(AAb), 该函数用于比较*this与b的大小,若两者含有元素的个数n相同,并且数组中前n个元素值对应相同,则认为两者相等返回1,否则返回0。注意:用数组方式及for循环来实现该函数。输出结果如下:
a=b
a<>C
注意:部分源程序已存在文件testl7_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数Compare的花括号中填写若干语句。
文件testl7_2.cpp的内容如下:
#include<iostream.h>
#include<stdlib.h>
class AA
int *a;
int n;
int MS;
public:
void InitAA(int aa[], int nn, int ms)
if(nn>ms)
cout<<"Error!"<<end1;
exit(1);
MS=ms;
n=nn;
a=new int[MS];
for(int i=0; i<n; i++) a[i]=aa[i];
int Compare(AA b);
;
int AA::Compare(AA b)
void main( )
AA a,b,c;
int x[]=1,2,3,4,5;
int y[]=1,2,3,6,7;
int z[]=1,2,5,7,9;
- a. InitAA(x,3,5);
- b. InitAA(y,3,5);
- c. InitAA(z,3,5);
if (a.Compare(b))
cout<<"a=b"<<end1;
else
cout<<"a<>b"<<end1;
if (a.Compare(c))
cout<<"a=c"<<end1;
[填空题]请补充main函数,该函数的功能是:打印出1~1000中满足:个位数字的立方等于其本身所有数。
本题的结果为;1 64 125 216 729
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数main的横线上填入所编写的若干表达式或语句。
试题程序:
#include <stdio .h>
main ( )
{
int i,g;
clrscr ( );
for (i=1; i<1000; i++)
{
g= 【1】 ;
if( 【2】 )
printf ("%4d", i);
}
}
[填空题]请补充main函数,该函数的功能是:打印出1~1000中满足:个位数字的立方等于其本身所有数。
本题的结果为;1 64 125 216 729
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数main的横线上填入所编写的若干表达式或语句。
试题程序:
#include <stdio .h>
main ( )
int i,g;
clrscr ( );
for (i=1; i<1000; i++)
g= 【1】 ;
if( 【2】 )
printf ("%4d", i);
[填空题]请补充main( )函数,该函数的功能是:打印出1~10000中满足个位数字的立方等于其本身的所有数。
本题的结果为:1 64 125 216 729
注意:部分源程序已给出。
请勿改动主函数main和其他函数中的任何内容。
试题程序:
#include<stdlib.h>
#include<stdio.h>
void main( )
int i, k;
system("CLS");
for(i=1; i<10000; i++)
k= (1) ;
if( (2) )
printf("%4d", i);
[填空题]请补充函数fun( ),该函数的功能是;删除字符数组中小于等于指定字符的字符,指定字符从键盘输入,结果仍保存
例如,输入“abcdefghij”,指定字符为‘d’,则结果输出“defghij”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include <stdio. h>
#define N 80
void fun (char s[], char ch)
int i=0, j=0;
while (s [i] )
if (s Iii<ch)
【1】 ;
else
【2】
i++;
【3】
main ( )
char str [N], ch;
clrscr ( );
printf("/n Input a string:/n");
gets (str);
printf("/n*** original string ***/n");
puts (str);
printf("/n Input a character:/n");
scanf ("%c", &ch);
fun(str, ch);
printf("/n*** new string ***/n");
puts (str);
[简答题]【说明】
给定函数fun的功能是:将从键盘上输入的每个单词的第一个字母转换为大写字母,输入时各单词必须用空格隔开,用“.”结束输入。
【函数】
int fun(char *c,int status)
if( (1) ==’’)
return 1;
else
if( (2) && (3) && (4) )
(5) =’A’-’a’;
return 0;
main( )
int flag=1;
char ch;
printf("请输入一字符串,用点号结束输入!/n");
do
ch=getchar( );
flag=fun(&ch,flag);
putchar(ch);
while(ch!=’.’);
printf("/n");