闲,做个练习看看...
#include <stdio.h>#include <stdlib.h>
typedef struct R{
int v1,v2,prdt;
struct R *NextRs;
}Rs;
typedef struct T{
Rs *NextRs;
struct T *NextTm;
}Tm;
//=========================================================================
void CreateTm(Tm **pTm,int Nums);
void PRN_Tm(Tm *pTm);
//=========================================================================
int main(void)
{
int n = 9;
Tm *pTm;
CreateTm(&pTm,n);
PRN_Tm(pTm);
system("pause");
return 0;
}
//=========================================================================
void CreateTm(Tm **pTm,int Nums)
{
int i,j;
Tm *pa = NULL,*pta = NULL;
Rs *pb = NULL,*ptb = NULL;
*pTm = NULL;
for(i = 1;i <= Nums;i++)
{
if(!(pa = (Tm *)malloc(sizeof(Tm))))
{printf("\nERROR!");exit (1);}
pa->NextTm = NULL;
pa->NextRs = NULL;
for(j = i;j <= Nums;j++)
{
if(!(pb = (Rs *)malloc(sizeof(Rs))))
{printf("\nERROR!");exit (1);}
pb->v1 = i;
pb->v2 = j;
pb->prdt = i*j;
pb->NextRs = NULL;
if(pa->NextRs == NULL)
{ptb = pa->NextRs = pb;continue;}
ptb->NextRs = pb;
ptb = ptb->NextRs;
}
if(*pTm == NULL) {*pTm = pta = pa;continue;}
pta->NextTm = pa;
pta = pta->NextTm;
}
}
//=========================================================================
void PRN_Tm(Tm *pTm)
{
Tm *p = pTm;
Rs *q = NULL;
while(p != NULL)
{
q = p->NextRs;
while(q != NULL)
{
printf("%d×%d=%2d ",q->v1,q->v2,q->prdt);
q = q->NextRs;
}
p = p->NextTm;
printf("\n\n");
}
}
//=========================================================================