以下程序的功能是输入两个字符串,将其中最长的字符串输出。
#include
#include
int main()
{
char ch1[10],ch2[10];
gets(ch1);
gets(ch2);
if(strcmp(ch1,ch2)>0)
puts(ch1);
else
puts(ch2);
return 0;
}
#include
#include
int main()
{
char ch1[10],ch2[10];
gets(ch1);
gets(ch2);
if(strcmp(ch1,ch2)>0)
puts(ch1);
else
puts(ch2);
return 0;
}
举一反三
- 下面的程序是实现两个字符变量的互换,若ch1输入a,ch2输入b,则程序运行时正确的输入是()(注:<回车>代表输入一个回车键) #include"stdio.h" main() { char ch1,ch2,ch3; scanf("%c%c",&ch1,&ch2); ch=ch1; ch1=ch2; ch2=ch; printf("ch1=%c,ch2=%c ",ch1,ch2);}
- 已知ch1='a',ch2='B',ch3='5',执行C语句if (ch1 >= ch2) ch= ch1-32 ; else if(ch1 <= ch3) ch = ch3+16 ; else ch= ch2+32 ;后,ch的值是
- 以下是一个字符串输入输出程序段: char ch1[10],ch2[10]; gets(ch1); gets(ch2); if(strlen(ch1)>strlen(ch2)) puts(ch1); else puts(ch2); 下列关于程序功能的描述,正确的是________。
- 有以下程序 #include main( ) { char ch[] = "abc"; ch[0] ^= ch[0]; ch[1] |= ch[1]; ch[2] &= ch[2]; printf("%d%c%c\n",ch[0],ch[1],ch[2]); } 程序运行后的输出结果是
- 以下是一个字符串输入输出程序段: char ch1[10],ch2[10]; gets(ch1); gets(ch2); if(strcmp(ch1,ch2)>0) puts(ch1); else puts(ch2);下列关于程序功能的描述,正确的是________。 A: 输入两个字符串,然后按照输入顺序依次输出这两个字符串 B: 输入两个字符串,将其中的大字符串输出 C: 输入两个字符串,将其中的小字符串输出 D: 输入两个字符串,将其中最长的字符串输出