| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1795 人关注过本帖
标题:系统输出随机数求和与平均数!与大家共享!
只看楼主 加入收藏
zhangfeng
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2005-3-20
收藏
 问题点数:0 回复次数:8 
系统输出随机数求和与平均数!与大家共享!

using System; using System.Collections; class count { static void Main() { Console.WriteLine("P INPUT NUM YOU WANT:"); int a=int.Parse(Console.ReadLine()); int[] all=new int[a]; decimal sum=0; int b=0;

Random r=new Random(); ArrayList aa=new ArrayList(); for(decimal i=0;i<a;i++) { b=r.Next(0,100); Console.WriteLine(b+","); aa.Add(b); sum+=b; } Console.WriteLine("数组的和:"+sum); Console.WriteLine("平均数:"+sum/a); System.Threading.Thread.Sleep(10000); }

}

搜索更多相关主题的帖子: 随机数 平均数 sum Console 
2005-04-13 22:21
shiuly
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2005-4-7
收藏
得分:0 
确信没错误吗?
int[] all=new int[a]; //定义一个名为all的数组

ArrayList aa=new ArrayList();
这里怎么是ArrayList了?

是不是错了啊???
2005-04-13 22:30
梦幻情缘
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:769
专家分:20
注 册:2005-4-4
收藏
得分:0 
这样的贴子已经有人贴过了.
2005-04-13 22:38
shanji
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2005-1-23
收藏
得分:0 
2005-04-15 00:06
yushengou
Rank: 1
等 级:新手上路
帖 子:401
专家分:0
注 册:2005-3-30
收藏
得分:0 
ArrayList aa=new ArrayList();
  aa.Add(b);
在这个程序中这两句完全可以不要

我是初学者,希望大家能多多帮助我 /bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://bbs./bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif');}" onmousewheel="return imgzoom(this);" alt="" />
2005-04-15 09:10
shenying
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2005-3-24
收藏
得分:0 
恩,我做了和你一个相似的!

2005-04-15 22:10
nighmore
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2005-4-5
收藏
得分:0 
听我一句,生成随机数不要用System.Random()
用System.Security.Cryptography提供的RNGCryptoServiceProvider类才是正道。

2005-04-15 23:09
shiuly
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2005-4-7
收藏
得分:0 

using System; using System.Collections;

namespace xl3 {

class Class1 {

[STAThread] static void Main(string[] args) { xx.f(); } class xx { public static int n; public static void f() { Console.WriteLine("請您輸入一個數"); n=int.Parse(Console.ReadLine()); int []arr=new int[n]; int m=0,sum=0; Random r=new Random(); for(int a=0;a<n;a++) { m=r.Next(0,100); arr[a]=m; sum+=m; } for(int a=0;a<n;a++) Console.WriteLine("arr[{0}]={1}",a,arr[a]); Console.WriteLine("和為"+sum); Console.WriteLine("平均數為"+sum/n); } } } } 这个是我做的,大家看看怎么样

2005-04-15 23:44
唐伯猫
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:5323
专家分:58
注 册:2005-8-9
收藏
得分:0 

这么好的东西,发过再发也不为过。


<iframe name="alimamaifrm" frameborder="0" marginheight="0" marginwidth="0" border="0" scrolling="no" width="300" height="170" src="/go/app/tbk_app/chongzhi_300_170.php?pid=mm_28854300_2441872_11377541&page=chongzhi_300_170.php&size_w=300&size_h=170&stru_phone=1&stru_game=1&stru_travel=1" ></iframe>
2005-12-02 11:23
快速回复:系统输出随机数求和与平均数!与大家共享!
数据加载中...
 
   



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

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