粉面菜蛋哈哈哈 2022-12-23 15:13 采纳率: 0%
浏览 20

关于#c语言#的问题:倒顺字母字符串#include <stdio.h>

倒顺字母字符串

img

#include <stdio.h>
const     char str[50]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
int main()
{
    int n;
    scanf("%d",&n);
    if(n>=1&&n<=26)
    {        
    if(n%2==0)
    {
    for(int i=0;i<n;i++)
    printf("%c ",str[i]);
        for(int j=n-1;j>=0;j--)
        {
            if(j!=0)
            printf("%c ",str[j]);
            else
            printf("%c",str[j]);
        }
    }
    else
    {
        for(int i=0;i<n;i++)
        printf("%c ",str[i]);
        for(int j=n-2;j>=0;j--)
        {
            if(j!=0)
            printf("%c ",str[j]);
            else
            printf("%c",str[j]);
        }
    }
    }
    return 0;
}
俺这样为什么不行😭🙃
  • 写回答

3条回答 默认 最新

  • 浪客 2022-12-23 15:48
    关注
    
    #include <stdio.h>
    
    int main()
    {
       int n;
       scanf("%d", &n);
       char c = 'a';
       if (n >= 1 && n <= 26)
       {
          for (int i = 0; i < n; i++)
             printf("%c ", c++);
          c -= 2;
          for (int i = n - 1; i > 0; i--)
             printf("%c%c", c--, (i > 1 ? ' ' : '\0'));
       }
       return 0;
    }
    
    
    评论

报告相同问题?

问题事件

  • 创建了问题 12月23日