拉丁方阵问题
拉丁方阵是一种n×n的方阵,方阵中恰有n种不同的元素,每种元素恰有n个,并且每种元素在一行和一列中 恰好出现一次。
著名数学家和物理学家欧拉使用拉丁字母来作为拉丁方阵里元素的符号,拉丁方阵因此而得名。
#include<stdio.h>
#include<malloc.h>
struct node
{
int data; //elementype表示一种数据类型,可能是int/char等等
struct node *next; //next 指针,用于链表结构指向下一个节点
};
typedef struct node node; //重定义struct node类型为node
node* Creat(int n);
int main()
{
int n;
int i;
int j;
node* head;
scanf("%d",&n);
head = Creat(n);
for(i = 0;i < n;i++)
{
j = n;
while(j)
{
printf("%d",head->data);
j--;
head = head->next;
}
printf("\n");
head = head->next;
}
return 0;
}
node* Creat(int n)
{
node *p = NULL;
node *head;
head =(node *)malloc(sizeof(node));
p = head;
node *s;
int i = 1;
if(0 != n)
{
while(i <= n)
{
s = (node*)malloc(sizeof(node));
s->data = i;
p->next = s;
p = s;
i++;
}
s->next = head->next;
}
free(head);
return s->next;
}