C++:用循环语句编程打印如下矩阵:
1 0 1 2 3 4 5 6
2 1 2 3 4 5 6 0
3 2 3 4 5 6 0 1
4 3 4 5 6 0 1 2
5 4 5 6 0 1 2 3
6 5 6 0 1 2 3 4
#include <stdio.h>
int main()
{
int a[8]= {1,0,1,2,3,4,5,6},i;
for(i=1; i<7; i++)
{
for(int j=0; j<8; j++)
{
a[j]%=7;
printf("%d",a[j]);
a[j]+=1;
}
printf("\n");
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int i,j,k=0,p;
int a[20];
for(j=0;j<7;j++)
a[j]=j;
for(i=1;i<=6;i++)
{ cout<<i<<" ";
p=i-1;
for(j=0;j<7;j++)
{cout<<a[p]<<" ";
p++;
p=p%7;
k++;
if(k==7)
break;
}
cout<<endl;
}
return 0;
}