编写程序输出矩阵

4、编写程序输出下面矩阵:
1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4

#include <stdio.h>
int main()
{
	int i,j;
	int a[5][5]={
  {1,2,3,4,5},{2,3,4,5,1},{3,4,5,1,2},{4,5,1,2,3},{5,1,2,3,4}};
	for(i=0;i<5;i++)
	{
	    for(j=0;j<5;j++) 
	    printf("%5d ",a[i][j]);
	    printf("\n");
	}
	return 0;
}
 
//改进:
#include <stdio.h>
int main(){
	int i,j;
	int a[5]={1,2,3,4,5};
	for(i=0;i<5;i++){
		for(j=0;j<5;j++)
			printf(" %d",a[(i+j)%5]);
		printf("\n");
	}
	return 0;
} 
    原文作者:long+
    原文地址: https://blog.csdn.net/return9/article/details/79687717
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞