matrix output

matrix output

Time Limit: 1000 ms  Memory Limit: 65536 KiB

Problem Description

Input n integers, output an n-row matrix of these integers.

Input

Enter a positive integer N (N<=20) in the first line, indicating the number of integers to be entered later.
Next, enter N integers in sequence.

Output

Based on the input integer, output regular n rows of data.

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

Hint

Source

Note: Pay attention to your own small mistakes, as well as the places where you make mistakes.

#include<stdio.h>   
intmain()   
{     
	int n,t;
	int i,j,k;
	int a[20];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++){
		if(i!=0){
		   t=a[n-1];
		      for(j=n-2;j>=0;j--){
		      	a[j+1]=a[j];
			  }	
			a[0]=t;
		}
		for(k=0;k<n;k++){
			if(k==0){
				printf("%d",a[k]);
			}
			else{
				printf(" %d",a[k]);
			}
		}
		printf("\n");
	}      
	return 0;   
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325162766&siteId=291194637