Chu279
2021-05-08 09:58
采纳率: 75%
浏览 444
已结题

求C语言题目! 将数组中的数逆序存放。输入一个正整数n(1<n≤10),再输人n个整数,存入数组a

求C语言题目! 将数组中的数逆序存放。输入一个正整数n(1
  • 收藏

2条回答 默认 最新

  • 正在学C++ 2021-05-08 10:25
    已采纳
    #include<stdio.h>
    int main(){
        int n;
        scanf("%d",&n);
        int a[n], b[n];
        for(int i=0;i<n;i++) scanf("%d",&a[i]);
        for(int i=0;i<n;i++) b[n-1-i] = a[i];
        for(int i=0;i<n;i++) printf("%d ",b[i]);
        return 0;
    }
    已采纳该答案
    打赏 评论
  • Eleven 2021-05-08 10:35
    int main()
    {
        #define MIN_COUNT   1
        #define MAX_COUNT   10
    
        int n = 0;
        int a[MAX_COUNT] = { 0 };
    
        printf("Input Count:\n");
        scanf_s("%d", &n);
    
        if ((n < MIN_COUNT) || (n > MAX_COUNT)) { return 0; }
    
        printf("Input Data:\n");
    
        for (int i = 0; i < n; ++i)
        {
            scanf_s("%d", &a[i]);
        }
    
        printf("\nBefore: ");
        for (int i = 0; i < n; ++i)
        {
            printf("%d ", a[i]);
        }
    
        for (int i = 0, j = n - 1; i < j; ++i, --j)
        {
            int temp = a[i];
            a[i] = a[j];
            a[j] = temp;
        }
    
        printf("\nAfter: ");
        for (int i = 0; i < n; ++i)
        {
            printf("%d ", a[i]);
        }
    
        return 0;
    }
    打赏 评论

相关推荐 更多相似问题