#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int data ;
struct node *next ;
} node ;
node *create (node *head , int rank)
{
head = (node *)malloc(sizeof(node));
node *tmp = head ;
node *add = NULL ;
for (int i = 0 ; i < rank ; i++)
{
add = (node *)malloc(sizeof(node));
add->data = i+1 ;
tmp->next = add ;
tmp = add ;
}
add->next = head->next ;
free(head);
return add->next ;
}
int main ()
{
node *head = NULL ;
node *output = NULL ;
node *tmp = NULL ;
int rank ;
printf("please input the rank of latin square: \n");
scanf("%d",&rank);
head = create(head , rank);
output = head ;
tmp = output ;
for (int j = 0 ; j < rank ; j++)
{
output = tmp ;
for (int k = 0 ; k < rank ; k++)
{
printf("%d ",output->data);
output = output->next ;
}
tmp = tmp->next ;
printf("\n");
}
return 0 ;
}