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;
}