比较两个字符串的大小,不许使用strcmp函数。
输入格式:
在两行分别输入两个长度小于20的字符串。在字符串中不要出现换行符,空格,制表符。
输出格式:
直接输出“>”或“<”或“=”,分别表示第一个字符串大于第二个字符串,第一个字符串小于第二个字符串,第一个字符串等于第二个字符串。
输入样例:
asd
abcd
输出样例:
>
输入样例:
asd
asd
输出样例:
=
输入样例:
cdfg
fgh
输出样例:
<
没什么难点,一个递归就可以解决
#include <stdio.h>
char strcmp1(const char s1[], const char s2[]);
int main() {
char s1[21], s2[21];
gets(s1);
gets(s2);
printf("%c", strcmp1(s1, s2));
}
char strcmp1(const char s1[], const char s2[]) {
int i = 0;
while (s1[i] != '\0' && s2[i]