c语言 输入一个字符串,分别将第奇数个,第偶数个字符选出放入两个数组中
答案:1 悬赏:60 手机版
解决时间 2021-01-11 17:14
- 提问者网友:我一贱你就笑
- 2021-01-10 23:09
c语言 输入一个字符串,分别将第奇数个,第偶数个字符选出放入两个数组中
最佳答案
- 五星知识达人网友:醉吻情书
- 2021-01-10 23:19
#include
#include
#include
#define N 1024
int main()
{
char a[N] = {0}, b[N] = {0}, c[N] = {0};
char *p = a;
int n;
printf("请输入字符串: ");
gets(a);
printf("\n");
while(*p) {
n = p - a;
if(n % 2 ==0)
b[n/2] = *p;
else
c[n/2] = *p;
p++;
}
b[n/2 + 1] = 0;
c[n/2 + 1] = 0;
printf("原始字符串是: %s\n", a);
printf("奇数位字符串是: %s\n", b);
printf("偶数位字符串是: %s\n", c);
getchar();
getchar();
return 0;
}
#include
#include
#define N 1024
int main()
{
char a[N] = {0}, b[N] = {0}, c[N] = {0};
char *p = a;
int n;
printf("请输入字符串: ");
gets(a);
printf("\n");
while(*p) {
n = p - a;
if(n % 2 ==0)
b[n/2] = *p;
else
c[n/2] = *p;
p++;
}
b[n/2 + 1] = 0;
c[n/2 + 1] = 0;
printf("原始字符串是: %s\n", a);
printf("奇数位字符串是: %s\n", b);
printf("偶数位字符串是: %s\n", c);
getchar();
getchar();
return 0;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯