大家看看这个C 代码怎么样?
要求是用循环链表方式制作一种彩票选号器。要求1)体育彩票(如10选7)的7个号可以重复
(2)建议用首尾相连的链式结构,这样可以更逼真地模拟“摇奖”过程;而每个号的“摇动”次数可用随机数来确定。 #include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct node
{
int data;
struct node *link;
};
int main()
{
int i,j;
struct node *p,*q,*h;
h=p=(struct node *)malloc(sizeof(struct node));
for(i=0;i<9;i++)
{
p->data=i;
q=(struct node *)malloc(sizeof(struct node));
p->link=q;
p=q;
}
p->data=i;
p->link=h;
srand(time(NULL));
for(i=0;i<7;i++)
{
for(j=0;j<rand()%100;j++)
p=p->link;
printf("%d",p->data);
}
printf("\n");
}
有何不妥?如何改进?把代码写下 好么??谢谢了 --------------------编程问答-------------------- --------------------编程问答-------------------- 看看 --------------------编程问答-------------------- 大家说说什么不足改下嘛
谢谢了啊
补充:.NET技术 , C#