编一个程序,将两个字符串s1和s2比较,如果s1>s2
2个回答
展开全部
#include
"stdio.h"
main()
{
char
s1[100],s2[100];int
i;
printf("input
string
s1:\n");
gets(s1);
printf("input
string
s2:\n");
gets(s2);
for(i=0;s1[i]!='\0'
&&
s2[i]!='\0';i++)
{
if(s1[i]==s2[i])
continue;
if(s1[i]<s2[i])
{printf("
s1
<
s2
:
-%d\n",abs(s1[i]-s2[i]));
break;}
else
{printf("
s1
>
s2
:
%d\n",abs(s1[i]-s2[i]));
break;}
}
if(s1[i]==s2[i])
printf("
s1
=
s2\n");
}
"stdio.h"
main()
{
char
s1[100],s2[100];int
i;
printf("input
string
s1:\n");
gets(s1);
printf("input
string
s2:\n");
gets(s2);
for(i=0;s1[i]!='\0'
&&
s2[i]!='\0';i++)
{
if(s1[i]==s2[i])
continue;
if(s1[i]<s2[i])
{printf("
s1
<
s2
:
-%d\n",abs(s1[i]-s2[i]));
break;}
else
{printf("
s1
>
s2
:
%d\n",abs(s1[i]-s2[i]));
break;}
}
if(s1[i]==s2[i])
printf("
s1
=
s2\n");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询