llgd.net
当前位置:首页 >> 产生50个随机整数程序 >>

产生50个随机整数程序

#include "stdlib.h" #include"stdio.h" #include"time.h" void main() { int n ,a[50],i,j,t; srand(time (NULL)); for(i=0;i

[-50,100]的整数没有超出char型的范围,故声明一个200元素的char型数组来完成,以节省空间开销,输出时强制为int型即可。用rand函数产生0~150的随机数减50来满足[-50,100]的要求。在将数据存入数组时,正数从前向后存储,负数从后向前存储,以达...

实现思路:生成50-100之间的随机数(包括50,包含100),之后循环k次分别输出即可: int k = 5; for(int i = 0;i

Dim n As Integer, i As Integer, x As Integer Dim s1 As String, s2 As String Randomize For i = 1 To 50 x = Int(Rnd * 50) + 1 s1 = s1 & x If i Mod 10 = 0 Then s1 = s1 & vbCrLf Else s1 = s1 & " " End If If x Mod 6 = 2 Then n = n +...

Private Sub Cmd_ok_Click() Const N = 50 Dim a(N) Randomize For i = 1 To N a(i) = 60 + Int(Rnd * 41) Next i Max = a(1): Min = a(1): Sum = 0 For i = 1 To N If Max < a(i) Then Max = a(i) If Min > a(i) Then Min = a(i) Sum = Sum + a...

Private Sub Command1_Click() Dim a(1 To 50) As Integer Dim n As Integer Randomize For i = 1 To 50 a(i) = Int(Rnd * 100 + 1) If a(i) < 60 Then Print a(i); n = n + 1 If n Mod 10 = 0 Then Print End If Next i End Sub

Dim a(1 To 50) As Integer, b(1 To 9) As Integer Dim i As Integer, j As Integer Randomize For i = 1 To 9 b(i) = 0 '初始化数组 Next For i = 1 To 50 a(i) = Int(90 * Rnd + 10) '产生随机数 For j = 1 To 9 '判定范围存入数组 If a(i) > ...

Private Sub Command1_Click() Dim a(29) As Integer, tmp As Integer Dim i As Integer, j As Integer Randomize Time For i = 0 To 29 a(i) = Int(Rnd * 71) + 30 Next For i = 0 To 29 For j = i To 29 If a(i) > a(j) Then tmp = a(i) a(i) ...

由于题目不完整,我只是猜想你要的结果 import java.util.Arrays;import java.util.Random;public class SumTest {public static void main(String[] args) {Random r = new Random();int[] arr = new int[50];int start = 10, end = 100, max ...

Private Sub Command1_Click() Dim a(1 To 10) As Integer Dim i As Integer, j As Integer Print "随机取到的10个50-100(包括50和100)的随机整数为" For i = 1 To 10 Randomize a(i) = Int(Rnd() * 51 + 50) Print a(i); Next i Print Print "...

网站首页 | 网站地图
All rights reserved Powered by www.llgd.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com