编程彩票
㈠ vb编程彩票随机问题
Private Sub Command1_Click()
Dim i, a(34), b(7)
Randomize: Cls
For i = 1 To 7
b(i) = Int(Rnd * 34 + 1)
If a(b(i)) Then i = i - 1 Else a(b(i)) = 1
Next
Print "34 选 7组 福利彩票系统,中奖号码:"
For i = 1 To 7
Print b(i)
Next
End Sub
㈡ java如何编程福利彩票30选7,我自己编的但是不知道有什么错误,希望帮我纠正一下,标注一下我的错误
你这个逻辑很混乱啊,数组a没有初始化,i也不是全局变量。全局变量和局部变量用的很乱。这个程序不能用
public static void main(String[] args){
Random r=new Random();
for(i=0;i<7;i++){//i没有初始化
a[i]=1+r.nextInt(30);//a[]没有初始化
while(true)
{
panDuan(a[i]);
if(i==j) break;//j不是全局变量,这里不能用
}
}
Arrays.sort(a);//这里排序干啥?七彩乐规则我不太懂
for(int k=0;k<7;k++){
System.out.print(a[k]+" ");}
}
private static void panDuan(int b) {
for(int j = 0;j<i;j++)
if(a[j]==b) break;//a[]不是全局变量,这里不能调用
// TODO Auto-generated method stub
}
}
你说下具体规则,我把程序写好给你吧
㈢ vb编程,生成N组22选5的彩票号码组(每组有不同的5个数字组成,且每个数码只能取1~22之间的数)
1、首先打开“Microsoft Visual Basic 6.0 中文版”,选择“标准 EXE”,并单击“打开”按钮,进入软件界面。
㈣ c语言程序设计——彩票问题
以下的 C 小程序将输出所有 28 个和值的出现的概率(输出贴在程序下面)。
可见概率最高 0.075,最低 0.001,所以已开出的 1000 期彩票中出现频率最高的和值是 13 和 14,
连续未出现期数最长的和值则是 0 和 27 (假设实际概率和理论概率吻合)。
#include<stdio.h>
/* 返回 number 中所有数字的和 */
unsigned sumOfAllDigits( unsigned number );
void main( ) {
/* 最低和值是 0,最高和值是 27,所以共有 28 个和值。*/
#define NUMBER_OF_SUM 28
unsigned chance[ NUMBER_OF_SUM ] = { 0 },
i;
for ( i = 0; i <= 999; i++ )
++chance[ sumOfAllDigits( i ) ];
puts( "和值\t出现的概率" );
puts( "一一\t一一一一一" );
for ( i = 0; i < NUMBER_OF_SUM; i++ )
printf( "%2u\t%.3f\n", i, chance[ i ] / 1000. );
}
unsigned sumOfAllDigits( unsigned number ) {
unsigned sum = 0;
for ( ; number; number /= 10 )
sum += number % 10;
return sum;
}
一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
输出:
和值出现的概率
一一一一一一一
00.001
10.003
20.006
30.010
40.015
50.021
60.028
70.036
80.045
90.055
100.063
110.069
120.073
130.075
140.075
150.073
160.069
170.063
180.055
190.045
200.036
210.028
220.021
230.015
240.010
250.006
260.003
270.001
㈤ C++编程:写一个产生K组福彩M选N的机选彩票号码程序(如K=5, M=35, N=7,表示机选5组35选7的号码)。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
void selectsort(int *x, int n) {
int i, j, min,t;
for (i = 0; i < n - 1; i++) {
min = i;
for (j = i + 1; j < n; j++) {
if (*(x + j) < *(x + min)) min = j;
}
if (min != i) {
t = *(x + i);
*(x + i) = *(x + min);
*(x + min) = t;
}
}
}
void select(int m,int n,int k) {
int num[36],tmp[36],t;
char filename[] = "C:\\2011\\随机号码.txt"; // 选择你需要的路径
FILE *fp;
srand((unsigned)time(NULL));
fp = fopen(filename,"wt");
if(fp == NULL) {
printf("打开文件%s错。\n",filename);
exit(1);
}
for(int i = 0;i < k;++i) {
for(int j = 1;j <= m;++j) tmp[j] = j;
for(j = 0;j < n;++j) {
t = (unsigned)rand()%m + 1;
if(tmp[t] != 0) {
num[j] = t;
tmp[t] = 0;
}
else --j;
}
selectsort(num,n);
for(j = 0;j < n;++j) {
fprintf(fp,"%02d ",num[j]);
printf("%02d ",num[j]);
}
fprintf(fp,"\n");
printf("\n");
}
fclose(fp);
}
int main() {
int m,n,k;
printf("被选号码数 : ");
scanf("%d",&m);
printf("可选号码数 : ");
scanf("%d",&n);
printf("所选组数 : ");
scanf("%d",&k);
select(m,n,k);
return 0;
}
㈥ 编写程序生成一张彩票,彩票中包含7个1到36之间的随机数(允许出现重复数字),最后把彩票的所有数字打印
我只发个核心代码吧
for (int i1 = 1; i1 <= 36; i1++)
for (int i2 = 1; i2 <= 36; i2++)
for (int i3 = 1; i3 <= 36; i3++)
.....................................
for (int i7 = 1; i7 <= 36; i7++)
cout << i1 << " " << i2 << " " << ........<< i7 << endl;
你要枚举所有情况,情况总数是36的7次方,所以运行时间很长,可能需要大约1分钟。
并且所有情况都输出到文件的话,输出文件会很大
㈦ 3D彩票JAVA编程怎么写
importjava.util.ArrayList;importjava.util.List;importjava.util.Random;importjava.util.Scanner;publicclassLotto{publicstaticfinalintNUMBER=7;publicstaticvoidmain(String[]args){List<Integer>userNumbers=newArrayList<Integer>();Scannerscanner=newScanner(System.in);inti=1;while(i<8){System.out.println("输入第"+i+"个数字:");userNumbers.add(scanner.nextInt());i++;}System.out.println(prize(userNumbers.toArray(newInteger[NUMBER])));}privatestaticInteger[]generateLotto(){List<Integer>lottoNumbers=newArrayList<Integer>();Randomrand=newRandom();intlottoNumber,i=0;while(i<NUMBER){lottoNumber=rand.nextInt(35)+1;if(!lottoNumbers.contains(lottoNumber)){lottoNumbers.add(lottoNumber);i++;}}returnbubbleSort(lottoNumbers.toArray(newInteger[NUMBER]));}privatestaticInteger[]bubbleSort(Integer[]array){for(inti=0;i<array.length;i++){for(intj=0;j<array.length-i-1;j++){if(array[j]>array[j+1]){inttemp=array[j+1];array[j+1]=array[j];array[j]=temp;}}}returnarray;}publicstaticStringprize(Integer[]userNumbers){intcount=0;Integer[]lottoNumbers=generateLotto();for(Integeri:userNumbers){for(Integerj:lottoNumbers){if(i==j){count++;}}}return"猜对了"+count+"个彩票号码";}}
输入第1个数字:
5
输入第2个数字:
14
输入第3个数字:
19
输入第4个数字:
24
输入第5个数字:
33
输入第6个数字:
34
输入第7个数字:
27
猜对了3个彩票号码
㈧ VB彩票程序设计
新建一个单窗体的工程,在上面画出七个TEXTBOX,最好是一个控件数组,这样编程时容易控制,再建一个COMMOND BUTTON,将CAPTION改为“随机产生”。在程序运行后,每点击一下COMMAND1,将随机产生一组数字并按从小到大的顺序显示在文本框中。下面就是程序部分:Dim NumArray(1 To 7) As Integer′通用中定义
Private Sub Command1_Click()
Dim i, j, N As Integer
For i = 1 To 7
NumArray(i) = 0
Next i
Randomize
NumArray(1) = Fix(1 + 32 * (Rnd()))
j = 1
Do
N = Fix(1 + 32 * (Rnd()))
For i = 1 To j
If N = NumArray(i) Then
Exit For ′重复时
ElseIf i = j Then ′未重复时
NumArray(i + 1) = N
j = j + 1
Exit For
End If
Next i
Loop While j < 7
PopSort ′升序排列
For i = 1 To 7
Text1(i - 1).Text = NumArray(i)
Next i
End Sub
Private Sub PopSort() ′气泡排序法
Dim i, j, Temp As Integer
For i = 7 To 2 Step -1
For j = 7 - 1 To 1 Step -1
If i >= 7 - j + 1 Then
If NumArray(j + 1) < NumArray(j) Then
Temp = NumArray(j)
NumArray(j) = NumArray(j + 1)
NumArray(j + 1) = Temp
End If
End If
Next j
Next i
End Sub
㈨ JAVA彩票编程:
package demo;import java.util.Random;public class Demo {
public static void main(String[] args) {
long x=0xfffL;
System.out.println(x);
Random r = new Random();
int a = (r.nextInt(33)+1);
int b = 0;
do{
b = r.nextInt(33)+1;
}while(b ==a);
int c = 0;
do{
c = r.nextInt(33)+1;
}while(c==a||c==b);
int d = 0;
do{
d = r.nextInt(33)+1;
}while(d==a||d==b||d==c);
int e = 0;
do{
e = r.nextInt(33)+1;
}while(e==a||e==b||e==c||e==d);
int f = 0;
do{
f = r.nextInt(33)+1;
}while(f==a||f==b||f==c||f==d||f==e);
int h = r.nextInt(16)+1;
System.out.println("红球号码:"+a+" "+b+" "+c+" "+d+" "+e+" "+f+" "+"蓝球号码:"+h);
}
}
//r.nextInt(33)+1 是产生1-33随机数的 思想是先产生随机数后判断相等,有相等则继续循环
㈩ 编写买彩票程序。编程让计算机随机产生7个1~30的整数,要求每次产生的7
祝册送宋rm比的 jjj.ee/rme7
static void Main(string[] args)
{
string i = null;
do
{
Console.Write("请输入整数(范围1~100)\n要退请输入0否则输入1");
i = Console.ReadLine();
if (i.Trim().Equals("0"))
{
return;
}
} while (!i.Trim().Equals("1"));
start:
Random ra = new Random();
int rndInt = ra.Next(1, 100);
int input = 0;
do
{
Console.Write("输入猜数值:");
i = Console.ReadLine();
if (!int.TryParse(i, out input))
{
continue;
}
if (input > rndInt)
{
Console.Write("猜\n\n");
}
else if (input < rndInt)
{
Console.Write("猜\n\n");
}
} while (input != rndInt);
Console.Write("恭喜猜\n\n");
do
{
Console.Write("若继续猜测输入Y,若退则输入N!\n请输入:");
i = Console.ReadLine();
if (i.Trim().Equals("n", StringComparison.OrdinalIgnoreCase))
{
return;
}
if (i.Trim().Equals("y", StringComparison.OrdinalIgnoreCase))
{
goto start;
}
} while (!i.Trim().Equals("1"));
}