[C语言生成一个0 100的随机数]一、C++获取随机数的方法rand()方法是C++获取随机数的方法,可以通过srand()方法获取系统的时间,用系统时间作为判断依据,生成随机数,随机数的大小通过rand()方法获取的值,进行取余后...+阅读
数字排序小游戏Option Explicit Dim Label2X As Integer '记录标签控件数组中要移动的e799bee5baa6e4b893e5b19e31333330356265标签控件左上角X的位置 Dim Label2Y As Integer '记录标签控件数组中要移动的标签控件左上角Y的位置'让标签数组中的每个标签控件上显示的数字是随机的,无重复的Private Sub Init() Randomize Dim a
(7) As Integer Dim i As Integer, k As Integer Label1.Caption = "" For i = 0 To 7 a(i) = i Next For i = 0 To 7 k = Int(Rnd * 8) Do While a(k) = -1 'a(k)=-1表示该数组元素对应的数字已经被使用过了 k = Int(Rnd * 8) '重新生成k的值,直到a(k)的值不等于-1 Loop Label2(i).Caption = Trim(Str(a(k))) a(k) = -1 'a(k)的值已经使用了,不能再用,重新赋值为-1与其他的元素值相区别 Next iEnd SubPrivate Sub Command1_Click() Dim x As Integer, y As Integer Dim z As Integer Init Picture1.Enabled = True '让空白标签Label1出现的位置随机 Randomize '记录下空白标签Label1的位置 x = Label1.Left y = Label1.Top z = Int(Rnd * 8) '将空白标签Label1和标签控件数组任一控件交换位置 Label1.Move Label2(z).Left, Label2(z).Top Label2(z).Move x, y Command1.Enabled = FalseEnd SubPrivate Sub Command2_Click() EndEnd SubPrivate Sub Form_Load() Dim i As Integer Picture1.Enabled = False '在标签中显示游戏说明信息 Label3.Caption = "如左图所示,将数字按0-7顺" & vbCrLf & vbCrLf & "序依次排列,即取得胜利。" '在标签中显示排列规则后的数字顺序 Label1.Caption = 0 For i = 0 To 6 Label2(i).Caption = i + 1 NextEnd SubPrivate Sub Label1_DragDrop(Source As Control, x As Single, y As Single) Dim Label1X As Integer '记录空白控件Label1左上角X的位置 Dim Label1Y As Integer '记录空白控件Label1左上角Y的位置 Dim flag
(3) As Boolean '获取空白控件Label1的位置 Label1X = Label1.Left Label1Y = Label1.Top '要移动的控件位于空白控件Label1的正左侧 flag(0) = (Label2X = Label1X - Source.Width) And (Label2Y = Label1Y) '要移动的控件位于空白控件Label1的正右侧 flag
(1) = (Label2X = Label1X + Source.Width) And (Label2Y = Label1Y) '要移动的控件位于空白控件Label1的正上方 flag
(2) = (Label2X = Label1X) And (Label2Y = Label1Y - Source.Height) '要移动的控件位于空白控件Label1的正下方 flag
(3) = (Label2X = Label1X) And (Label2Y = Label1Y + Source.Height) If flag(0) Or flag
(1) Or flag
(2) Or flag
(3) Then Label1.Move Label2X, Label2Y Source.Move Label1X, Label1Y End If WinEnd SubPrivate Sub Label2_MouseDown(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single) If Button = vbLeftButton Then '如果按下鼠标左键 '记录下要拖动控件的位置 Label2X = Label2(Index).Left Label2Y = Label2(Index).Top Label2(Index).Drag 1 '启动拖动操作 End IfEnd SubPrivate Sub Label2_MouseUp(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single) Label2(Index).Drag 2 '结束拖动操作End SubPrivate Sub Win() Dim winner As Integer Dim i As Integer Dim answer As Integer '对于给定的标签控件数组中的任一标签控件,可以落在符合要求(对应位置应显示对应数字) '的八个位置中的任一位置 '利用循环语句对标签控件数组中的每个标签控件进行检查,如果其落在某一符号要求的位置, '则变量winner的值加1,如果所有标签控件都落在符号要求的位置,则变量winner的值应为8 For i = 0 To 7 If Label2(i).Left = 0 And Label2(i).Top = 0 And _ Label2(i).Caption = 0 Then winner = winner + 1 ElseIf Label2(i).Left = Label2(i).Width And Label2(i).Top = 0 And _ Label2(i).Caption = 1 Then winner = winner + 1 ElseIf Label2(i).Left = 2 * Label2(i).Width And Label2(i).Top = 0 And _ Label2(i).Caption = 2 Then winner = winner + 1 ElseIf Label2(i).Left = 0 And Label2(i).Top = Label2(i).Height And _ Label2(i).Caption = 3 Then winner = winner + 1 ElseIf Label2(i).Left = Label2(i).Width And Label2(i).Top = Label2(i).Height And _ Label2(i).Caption = 4 Then winner = winner + 1 ElseIf Label2(i).Left = 2 * Label2(i).Width And Label2(i).Top = Label2(i).Height And _ Label2(i).Caption = 5 Then winner = winner + 1 ElseIf Label2(i).Left = 0 And Label2(i).Top = 2 * Label2(i).Height And _ Label2(i).Caption = 6 Then winner = winner + 1 ElseIf Label2(i).Left = Label2(i).Width And Label2(i).Top = 2 * Label2(i).Height And _ Label2(i).Caption = 7 Then winner = winner + 1 End If Next i If winner = 8 Then MsgBox " 恭喜您,胜利了!", 0 + 64 + 0, "提示" Picture1.Enabled = False answer = MsgBox("还继续吗?", 4 + 32 + 0, "提示") If answer = vbYes Then Command1.Enabled = True Else End End If End IfEnd Sub
求文档:用vb编写文曲星中的猜数字游戏
代码工程已发至你邮箱Dim a(1 To 4)Private Sub Command1_Click()B = "0123456789"Randomizej = 10For i = 1 To 4d = Int(Rnd * (j - 1) + 1)a(i) = Mid(B, d, 1)B = Replace(B, a(i), "")j = j - 1NextEnd SubPrivate Sub Command2_Click()Print a
(1) & "" & a
(2) & "" & a
(3) & "" & a
(4)End SubPrivate Sub Form_Load()Text1.MaxLength = 4End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)If KeyAscii = 13 ThenDim B(1 To 4) For K = 1 To 4 B(K) = Mid(Text1, K, 1) Next For e = 1 To 4 If a(e) = B(e) Then l = l + 1 If l = 4 Then MsgBox "答案正确" Exit Sub End If For p = e + 1 To 4 If B(e) = a(p) Then m = m + 1 Next For p = e - 1 To 1 Step -1 If B(e) = a(p) Then m = m + 1 Next Next Print Text1 & Space
(5) & l & "A" & Space
(2) & m & "B" Text1.SelStart = 0 Text1.SelLength = 4 Text1.SetFocus End If End Sub...
谁可以帮我用VB编一个大家来找茬的小游戏啊
Private Sub Command1_Click()
Randomize
Dim Num As Long
Dim RightAnswer As Boolean
Dim InputNum As Long
Text1.Text = ""
Num = Int(Rnd * 1000) + 1
RightAnswer = False
Text1.Text = Text1.Text + "Here's a number between 1 and 1000. Can you guess it?" + vbNewLine
While RightAnswer = False
InputNum = InputBox("Enter a number")
If InputNum = Num Then
Text1.Text = Text1.Text & InputNum & " " & "You guessed it!" & vbNewLine
RightAnswer = True
ElseIf InputNum < Num Then
Text1.Text = Text1.Text & InputNum & " " & "Too Small" & vbNewLine
ElseIf InputNum > Num Then
Text1.Text = Text1.Text & InputNum & " " & "Too Large" & vbNewLine
End If
Wend
End Sub
以下为关联文档:
用C语言编写一个简单的图书管理小程序源代码如下: #include<iostream> #include<iomanip> #include<string> #include<fstream> #include<stdio.h> using namespace std; const int maxb=10000; //最多的图书 clas...
教你如何使用C语言编写简单小游戏编写程序,实现如下表所示的5-魔方阵。 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 5-魔方阵 问题分析 所谓“n-魔方阵”,指的是使用1〜n2共n2个自然...
用c语言编写一个简单的程序main() { int a,b,i; bool flag = true; for (i = 0; i < 6; i++) { scanf("%d", &a); if (flag) { b = a; flag = false; } else { if (b > a) b = a; } } prinf("%d", b); }...
求助C语言编写一个简单的程序#include "stdio.h" #include "conio.h" #include "stdlib.h" void main( ) { FILE *fp; int flag,t; printf("输入1为输入数据,0为求平均数并输出\n"); scanf("%d",&flag); if (flag) {...
用汇编语言编写一个简单程序1.计算U=(X+(Y*Z-100))/W 其中:X,Y,Z,W均为十六位有符号数。 程序如下: DATA SEGMENT X DW 10 ;16位变量 Y DW 20 Z DW 30 W DW 40 U DW ?,? DATA ENDS CODE SEGMENT ASSUME C...
c语言编写一个猜数字游戏同学你好! 下面是我自己做了一个,运行是成功的。希望对你有所帮助! #include<stdio.h> #include<stdlib.h> #include<math.h> #include<time.h> void main() { int i,j,cnt,gua...
用C语言编写一个具有简单界面的猜数字游戏分析: 先产生一个随机数N。 然后输入数I,如果i大于N,则提示大于信息。 如果I小于N,则提示小于信息。 直到I==N,则输出成功信息。 这是我用C语言写的。 环境: WIN-C ,TORBO C,如果是...
编写一个简单的C语言程序#include "stdio.h" #include "string.h" #define N 300 void main(){ char a[N],sum='\0'; int i=0,k; printf("input the number:"); scanf("%s",a); k=strlen(a); printf("%d",sum)...
谁会用C语言编写一个能产生随机数并用冒泡排序和二分查找显示你说产生一个随即数,还是产生很多随即数,然后排序?然后还要查找?查找什么数?题目说清楚ok? 产生50个随即数,然后排序可以办到,那么查找显示出什么数? 根据你的要求题意,程序如下,运行正...