|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
typedef struct s
{
int data;
struct s *next;
}node;
node *chushihua(int x); //初始化方阵
void shuchu(node *phode,int x); //输出方阵
void main()
{
int x;
node *phode;
printf("请输入几乘几的方阵(输入一个整数):");
scanf("%d",&x);
phode=chushihua(x);
tiaoshi(phode);
shuchu(phode,x);
}
node *chushihua(int x) //初始化方阵
{
int i;
node *hode,*p,*p2;
for(i=1; i<=x; i++)
{
p=(node *)malloc(sizeof(node));
if(i==1)
{
hode=p;
}
else
{
p2->next =p;
}
p->data =i;
p2=p;
}
p->next=hode;
return hode;
}
void shuchu(node *phode,int x) //输出方阵
{
int i,j;
node *p=phode;
for(i=1; i<=x; i++)
{
for(j=1; j<=x; j++)
{
printf(" %d",p->data);
p=p->next;
}
printf("\n");
p=p->next ;
}
printf("\n");
}
|
|