YTU oj 3209: 矩阵输出

版权声明:欢迎大佬批评指正!O(∩_∩)O https://blog.csdn.net/wyh1618/article/details/81298812

3209: 矩阵输出

Description

输入n个整数,输出由这些整数组成的n行矩阵。

Input

第一行输入一个正整数N(N<=20),表示后面要输入的整数个数。
下面依次输入N个整数。

Output

以输入的整数为基础,输出有规律的n行数据。

Sample Input

5
3 6 2 5 8

Sample Output

3 6 2 5 8
8 3 6 2 5
5 8 3 6 2
2 5 8 3 6
6 2 5 8 3
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
    int n,m,i,j,k;
    int a[99];
    int b[99];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        printf("%d ",a[i]);
    }
    printf("\n");
    for(i=0;i<n-1;i++)
    {
        k=a[n-1];
        for(j=0;j<n;j++)
        {
            if(j==0)
            {
                b[j]=k;
            }
            else
            {
                b[j]=a[j-1];
            }
            printf("%d ",b[j]);
        }
        for(k=0;k<n;k++)
        {
            a[k]=b[k];
        }
        printf("\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/wyh1618/article/details/81298812