|
发表于 2020-5-15 16:30:01
|
显示全部楼层
可能是:
#define N 30
#include "stdio.h"
#include <math.h>
#include "conio.h"
#include <stdlib.h>
int main()
{
int lucky[N][N],row[N],col[N];
int n,lucky_n,k,sum=0,i,j;
printf("请输入方阵阶数");scanf("%d",&n);
printf("请输入幸运数字");scanf("%d",&lucky_n);
k=lucky_n/n;
if(k==0)
printf("输入数值太小");
for(i=0;i<n;i++)
{
row[i] = rand()%k;
col[i] = rand()%k;
sum+=row[i]+col[i];
}
col[n-1]+=lucky_n-sum;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
lucky[i][j]=row[i]+col[j];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("%d\f",lucky[i][j]);
}
getch();
} |
|