C语言 编写程序,完成:从键盘上输入一个n*n数组各元素,把每行元素循环左移1位输出。
代码:
#include<stdio.h>
#include <string.h>
void main(){
int i,j;
int a[3][3];
for(i=0;i<3;i++)//输入数组
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
for(i=0;i<3;i++){
for(j=0;j<3;j++){
printf("%3d",a[i][(j+1)%3]);//右移一位输出
}
printf("\n");
}
}
输出结果:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190513185351102.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDA5OTAxMg==,size_16,color_FFFFFF,t_70)