您的位置:首页 > 其它

矩阵循环打印

2016-01-24 17:01 337 查看
输入任意的六位数字:如 1 2 3 4 5 6

打印结果如下:

1 2 3 4 5 6

6 1 2 3 4 5

5 6 1 2 3 4

4 5 6 1 2 3

3 4 5 6 1 2

2 3 4 5 6 1

例如输入 5 9 8 1 3 6

打印结果如下 :

5 8 9 1 3 6

6 5 8 9 1 3

3 6 5 9 8 1

1 3 6 5 9 8

8 1 3 6 5 9

9 8 1 3 6 5

.......

#include<stdio.h>
#include<stdlib.h>

int a[6] = {0};
void fun(int a[6]);  //每次循环,将数组循环后移一位
void result();

int main(void)
{

int flag = 1;

while(flag)
{
system("cls");
result();
printf("Whether to continue testing, yes 1   no 0  : ");
scanf("%d" , &flag);  //是否继续检测,是 输入 1 ,否 输入 0
}

system("PAUSE");
return 0;
}

void result()
{

printf("please input 6  number in a row :\n");
for(int i = 0 ; i < 6 ; i++)
{
scanf("%d",(a+i));
}

printf("result :\n");

for( i = 0 ; i < 6 ; i++)
{
for(int j = 0 ; j < 6 ; j++)
{
printf("%d\t",a[j]);
}

printf("\n");

fun(a);  //每循环依次,将数组数据循环后移一位

}

}

void fun(int a[6])
{
int temp = a[5];

for(int i = 5 ; i > 0; i--)
{
a[i] = a[i-1];
}

a[i] = temp;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: