69,375
社区成员
发帖
与我相关
我的任务
分享
Please input a number:10
1 2 6 7 15 16 28 29 45 46
3 5 8 14 17 27 30 44 47 64
4 9 13 18 26 31 43 48 63 65
10 12 19 25 32 42 49 62 66 79
11 20 24 33 41 50 61 67 78 80
21 23 34 40 51 60 68 77 81 90
22 35 39 52 59 69 76 82 89 91
36 38 53 58 70 75 83 88 92 97
37 54 57 71 74 84 87 93 96 98
55 56 72 73 85 86 94 95 99 100
Input n(0~50):10
82 81 80 79 78 77 76 75 74 73
83 50 49 48 47 46 45 44 43 72
84 51 26 25 24 23 22 21 42 71
85 52 27 10 9 8 7 20 41 70
86 53 28 11 2 1 6 19 40 69
87 54 29 12 3 4 5 18 39 68
88 55 30 13 14 15 16 17 38 67
89 56 31 32 33 34 35 36 37 66
90 57 58 59 60 61 62 63 64 65
91 92 93 94 95 96 97 98 99 100
Input n(0~50):10
1 2 3 4 5 6 7 8 9 10
36 37 38 39 40 41 42 43 44 11
35 64 65 66 67 68 69 70 45 12
34 63 84 85 86 87 88 71 46 13
33 62 83 96 97 98 89 72 47 14
32 61 82 95 100 99 90 73 48 15
31 60 81 94 93 92 91 74 49 16
30 59 80 79 78 77 76 75 50 17
29 58 57 56 55 54 53 52 51 18
28 27 26 25 24 23 22 21 20 19
杨辉三角:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
1 10 45 120 210 252 210 120 45 10 1
#include <stdio.h>
int main(void)
{
int a[10][10],round,i,n,road,x,y,count;
scanf("%d",&n);
road=n%2;
switch(road)
{
case 0:
count=1; for(round=1;round<=n/2;round++)
{
y=round-1;
for(i=round-1;i<=n-1-round;i++)
{
a[i][y]=count;
count++;
}
x=n-round;
for(i=round-1;i<=n-1-round;i++)
{
a[x][i]=count;
count++;
}
y=n-round;
for(i=n-round;i>=round;i--)
{
a[i][y]=count;
count++;
}
x=round-1;
for(i=n-round;i>=round;i--)
{
a[x][i]=count;
count++;
}
}
break;
case 1: count=1;
for(round=1;round<=(n-1)/2;round++)
{
y=round-1;
for(i=round-1;i<=n-1-round;i++)
{
a[i][y]=count;
count++;
}
x=n-round;
for(i=round-1;i<=n-1-round;i++)
{
a[x][i]=count;
count++;
}
y=n-round;
for(i=n-round;i>=round;i--)
{
a[i][y]=count;
count++;
}
x=round-1;
for(i=n-round;i>=round;i--)
{
a[x][i]=count;
count++;
}
}
a[(n-1)/2][(n-1)/2]=count;
break;
}
for(y=0;y<=n-1;y++)
{
for(x=0;x<=n-1;x++)
printf("%5d",a[x][y]);
printf("\n");
}
}
#include<string.>
int main(void)
{
int n,i,j=1,a[9][9],k=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=i-1;j<=2*n-1-i;j++)
{
a[k][j]=i;
a[j][k]=i;
a[j][2*n-k-2]=i;
a[2*n-k-2][j]=i;
}
k++;
}
for(i=0;i<(n*2-1);i++)
{
for(j=0;j<(n*2-1);j++)
printf("%d",a[i][j]);
printf("\n");
}
return 0;
}
#include <stdio.h>
#define MAX_SIZE 50
int main(void)
{
int a[MAX_SIZE][MAX_SIZE];
int i,j,n,count=1;
printf("请输入矩阵的阶数:\n");
scanf("%d",&n);
//初始化数组
for(i=0;i<n;i++)
for(j=0;j<n;j++)
a[i][j]=0;
//对剩余的进行赋值
//第一个元素进行赋值
i=0;j=0;
a[0][0]=count;
count++;
for(int m=1;m<=2*n-3;m++)//赋值的次数
{
//奇数行是从左下方至右上方赋值的
if(m%2)
{
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(i+j==m)
a[i][j]=count++;
}
//偶数行是从右上方至左下方赋值的
else
{
for(i=n-1;i>=0;i--)
for(j=n-1;j>=0;j--)
if(i+j==m)
a[i][j]=count++;
}
}
//最后一个元素赋值
i=n-1;j=n-1;
a[i][j]=count;
//输出矩阵
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("%-3d ",a[i][j]);
printf("\n");
}
return 0;
}
#include "stdio.h";
int sum(int n)
{
int i = 1;
int result = 0;
for( ; i < n; i++)
result += i;
return result;
}
int getnumber(int x, int y)
{
int result = 0;
int msg = 0;
if( x + y > 11 )
{
x = 11 - x;
y = 11 - y;
msg = 1;
}
result = sum( x + y - 1 );
result += ( ( x + y ) % 2 ? y : x);
if( msg )
{
result = 101 - result;
}
return result;
}
void main()
{
int x;
int y;
for( y = 1; y < 11; y++)
{
for( x = 1; x < 11; x++)
{
printf( "%d ", getnumber( x, y) );
if( 10 == x )
printf("\n");
}
}
getchar();
}
void practice2()
{
int arr[MAX][MAX] = {0};
cout << "Please input a number:";
int num,value = 1,i = 0, j = 0;
cin >> num;
j = num /2;
if(num % 2)
{
i = num /2;
}
else
{
i = num / 2 - 1;
}
int flag = 1;
arr[i][j] = value++;
while( value <= num * num)
{
while(flag == 1) //向左
{
if(j >= 0 && arr[i][j - 1] == 0)
{
arr[i][--j] = value++;
flag = 2;
}
else if(arr[i][j - 1] != 0)
{
flag = 4;
}
}
if(j < 0)
break;
while(flag == 2) //向下
{
if(i < num && arr[i + 1][j] == 0)
{
arr[++i][j] = value++;
flag = 3;
}
else if(arr[i + 1][j] != 0)
{
flag = 1;
}
}
if(i == num)
break;
while(flag == 3) //向右
{
if(j < num && arr[i][j + 1] == 0)
{
arr[i][++j] = value++;
flag = 4;
}
else if(arr[i][j + 1] != 0)
{
flag = 2;
}
}
if(j == num)
break;
while(flag == 4) //向上
{
if(i >= 0 && arr[i - 1][j] == 0)
{
arr[--i][j] = value++;
flag = 1;
}
else if(arr[i - 1][j] != 0)
{
flag = 3;
}
}
if(i < 0)
break;
}
for(i = 0; i < num; i++)
{
for(j = 0;j < num; j++)
{
cout<< setw(4) << arr[i][j];
}
cout << endl;
}
}
void practice11()
{
int arr[MAX][MAX] = {0};
cout << "Please input a number:";
int num,value = 1,i = 0, j = 0;
cin >> num;
bool flag = true;
while(value <= num * num)
{
if( i == 0 && flag && j != num - 1) //向右
{
arr[i][j++] = value++;
flag = false;
}
else //向下
{
arr[i++][j] = value++;
flag = false;
}
while( j != 0 && !flag && i != num - 1) //向左下
{
arr[i++][j--] = value ++;
}
if(j == 0 && !flag && i != num - 1) //向下
{
arr[i++][j] = value++;
flag = true;
}
else //向右
{
arr[i][j++] = value++;
flag = true;
}
while( i != 0 && flag && j != num - 1) // 向右上
{
arr[i--][j++] = value ++;
}
}
for(i = 0; i < num; i++)
{
for(j = 0;j < num; j++)
{
cout<< setw(4) << arr[i][j];
}
cout << endl;
}
}
#include <stdio.h>
#define MAX 20
int main()
{
int n,k,i,j,count=1;
char a[MAX][MAX];
printf("please input number of rows: ");
scanf("%d",&n);
for(k=0;k<n;k++)
for(i=k,j=0;(i>=0 && j>=0);i--,j++)
((k%2)? a[j][i]:a[i][j])=count++;
for(i=0;i<n-1;i++)
for(j=0;i+j<n-1;j++)
a[n-1-i][n-1-j]=n*n+a[0][0]-a[i][j];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++) printf("%d\t",a[i][j]);
printf("\n");
}
getch();
return 0;
}