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

产生50个随机整数程序

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

#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]的要求。在将数据存入数组时,正数从前向后存储,负数从后向前存储,以达...

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, sum = 0;for (int i = 0; i < arr.length; i...

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...

#include void main(){int i,j,a[7];for(i=0;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) ...

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

看代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 #include #include void print_arr (int* a, int n) { int i = 0; for (; i < n; ++i) { printf ("%d ", a[i]); if ((i+1) % 10 == 0) { pri...

#include #include #include void main() { int i,j; int x[50]; int n=50; FILE *fp; srand((unsigned)time(NULL)); // 用当前时间来产生随机数种子,这样每次用本程序产生的随机数序列 将不同,更随机。 for(i=0;i

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