| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 772 人关注过本帖
标题:我的程序 不止到错到那里!!
只看楼主 加入收藏
zhangfeng
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2005-3-20
收藏
 问题点数:0 回复次数:4 
我的程序 不止到错到那里!!

using System; public class nan { public int Sum(int[] list) { int all=0; foreach(int c in list) { all+=c; } return all; } static void Main() {

Console.WriteLine("请输入你需要0~~100的数的个数:"); int n=int.Parse(Console.ReadLine());

for(int a=0;a<=n;a++)//a从0到n,总共有n+1个数 { int i=0; Console.WriteLine("请输入你需要0~~100的数的+a+:"); int c=int.Parse(Console.ReadLine()); nan p=new nan(); int[] text=new int [n]; text[i]=c; int all = p.Sum(text);//Sum里面含有foreach语句,又在for语句中,循环了多少次啊?你自己算算 if(a==n) { Console.WriteLine(all); } else { continue; } } System.Threading.Thread.Sleep(10000); }

}

[此贴子已经被幻风幻云于2005-4-12 23:28:57编辑过]

搜索更多相关主题的帖子: return public color 
2005-04-11 21:45
幻风幻云
Rank: 1
等 级:新手上路
帖 子:762
专家分:0
注 册:2005-1-14
收藏
得分:0 
把你的程序目的写出来吧! 目前来说,你的程序可以运行,不知道你指的错误是什么?

2005-04-11 21:51
zhangfeng
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2005-3-20
收藏
得分:0 
我的目的是想设置一个可变的数组  想向里面输入几个数就输入几个数!最后得到他们的和!
2005-04-12 15:33
jacky
Rank: 1
等 级:新手上路
帖 子:104
专家分:0
注 册:2004-12-17
收藏
得分:0 
using System;
public class Sum_Test
{
 static int sum(ref int[] array)//注意,这个方法名不能与类名相同,我的实践为证
 {
  int sum=0;
  foreach(int pins in array)
  {
   sum+=pins;
  }
  return sum;
 }
 public static void Main()
 {
  
  Console.WriteLine ("你想算几个数的和:(0-100)");
  int i_number=int.Parse (Console.ReadLine ());
  int[] A=new int [i_number];
  for(int i=0;i&lt;i_number;i++)
  {
   Console.WriteLine ("请输入第{0}个数:",i+1);
   A[i]=int.Parse (Console.ReadLine ());
  }
  Console.WriteLine ("这{0}个数的和是{1}:",i_number,sum(ref A));
 }
}
仅供参考
2005-04-12 16:24
gggcorn
Rank: 1
等 级:等待验证会员
帖 子:12
专家分:0
注 册:2005-4-13
收藏
得分:0 
老兄门,高手门可不可以留qq号,或推荐几个群我们共同探讨,谢谢。
2005-04-13 18:23
快速回复:我的程序 不止到错到那里!!
数据加载中...
 
   



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

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