- /**
- * 函数功能:
- * 输入两个字符串,交叉输出字符串中元素。如:asdfg,123 输出a1s2d3fg
- */
- #include <stdio.h>
- #include <string.h>
- #define MAX 10
- int main()
- {
- char c1[MAX];
- char c2[MAX];
- int maxlength;
- int l1,l2;
- int i;
- printf("请输入第一个字符串(少于10个):");
- gets(c1);
- printf("请输入第二个字符串(少于10个):");
- gets(c2);
- l1 = strlen(c1);
- l2 = strlen(c2);
- if(l1>l2)
- maxlength = l1;
- else
- maxlength = l2;
- for(i=0;i<maxlength;i++)
- {
- if(i<l1)
- printf("%c",c1[i]);
- if(i<l2)
- printf("%c",c2[i]);
- }
- printf("\\n");
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/190620149797.html
来源: http://www.codesnippet.cn/detail/190620149797.html