| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 599 人关注过本帖
标题:请找出错误的地方,并解释解释谢谢!!!
只看楼主 加入收藏
guozhencai
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2005-3-9
收藏
 问题点数:0 回复次数:0 
请找出错误的地方,并解释解释谢谢!!!

#include <stdio.h> #include <time.h> #define MM 7/*彩票中号码的个数*/ #define NN 36/*备选数的个数*/

typedef int ElemTp;/*元素类型*/ typedef struct { ElemTp elem[MM+1]; int len;/*表长*/ }VoteTp;/*彩票号码表的类型*/

typedef struct { ElemTp elem[NN+1]; int len;/*表长*/ }SourceTp;/*备选数表的类型*/ SourceTp source;/*备选数表*/ InitializeVote(VoteTp*vote); InitializeSource(SourceTp*source); void SeqInsertVote(VoteTp*vote,int i,ElemTp x); int SeqLocate(VoteTp v,ElemTp x); VoteTp CreateAVote(); int RightNum(VoteTp vote,VoteTp answervote); main() { VoteTp vote; VoteTp answervote; int k,i; random(); InitializeSource(&source);/*初始化备选数表source:放入36个数,将表长值为36*/ answervote=CreateAVote();/*生成一组中奖号码*/ printf("\nPress Any Key to Continue,0 to exit!"); printf("\n Answer Numbers: "); for(i=1;i<=MM;i++) printf("%3d, ",answervote.elem[i]); printf("\n Your Vote Numbers --->>Right Numbers\n"); while(getch()!='0') { vote=CreateAVote();/*生成一张彩票vote*/ for(i=1;i<=MM;i++) printf(" %-2d ",vote.elem[i]); k=RightNum(vote,answervote);/*计算猜对号码的个数*/ printf(" --->> %d \n",k); } } InitializeVote(VoteTp*vote) {/*初始化彩票号码表vote,将其表长值为0*/ vote->len=0; } InitializeSource(SourceTp *Source) {/*初始化备选数表source,在表中放入1-36共36个数,将表长置为36*/ int i; for(i=1;i<=NN;i++) Source->elem[i]=i; Source->len=NN; } int SeqLocate(VoteTp v,ElemTp x) {/*在顺序表v中查找值为x的元素,返回该元素的位置序号,没有返回0*/ int j=1;/*查找的启始位置*/ while(j<=v.len&&v.elem[j]!=x) j++; if(j<=v.len)/*查找成功*/ return j; else /*查找不成功*/ return 0; } void SeqInsertVote(VoteTp*vote,int i,ElemTp x) { /*在顺序表*p的第i个数据元素之前插入数据元素x*/ VoteTp v; int j; v=*vote; if((i<1)||(i>v.len+1)) printf(" error number! "); else { /*将第i个元素及其后的所有元素后移*/ for(j=v.len;j>=i;j--) v.elem[j+1]=v.elem[j]; v.elem[i]=x;/*将元素x放置到第i个位置*/ v.len=v.len+1;/*表长加1*/ } *vote=v;/*插入元素后的顺序表*/ } VoteTp CreateAVote() { VoteTp vote; ElemTp k,temp; int i; InitializeVote(&vote); source.len=NN; for(i=1;i<=MM;i++) { k=random(source.len)+1; SeqInsertVote(&vote,vote.len+1,source.elem[k]); temp=source.elem[k]; source.elem[k]=source.elem[source.len]; source.elem[source.len]=temp; source.len=source.len-1; } return vote; } int RightNum(VoteTp vote,VoteTp answervote) { int i,k; k=0; for(i=1;i<MM;i++) if(SeqLocate(vote,answervote.elem[i])>0) k++; return (k); } 这道题我上次在这里发过 上次的那道题错误太多 我现在就把它修改一下 但是仍然有问题 运行上面的程序说找不到random函数 于是就给它加了 #include <stdio.h> 这么条语句 不料程序出现的错误更多 恳请高手赐教谢谢

[此贴子已经被作者于2005-10-8 16:02:19编辑过]

搜索更多相关主题的帖子: 解释 
2005-10-07 16:20
快速回复:请找出错误的地方,并解释解释谢谢!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014430 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved