c#里面的for语句的问题!

来源:百度知道 编辑:UC知道 时间:2024/04/29 11:40:48
用for语句实现下面的要求,任意输入5个数字都能计算出这5个数的和,并且可以提示继续输入.

我是c#的初学者,哪位懂的,帮帮忙!
谢谢了!
大哥,,,帮忙写下。。。偶很菜的!

用数组 把输入的数放到数组里 然后在垒加 然后把 继续输入的提示放到循环里面 就行了
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] number;
number = new string[5];
int count2=0;
string bbb;
do
{
for (int i = 0; i < 5; i++)
{
Console.WriteLine("输入第{0}个数字", i + 1);
number[i] = Console.ReadLine();
count2 = count2 + Convert.ToByte(number[i]);
}
Console.WriteLine("和为:{0}", count2);
Console.WriteLine("按y继续,其他键退出");
bbb = Console.ReadLine();
}
while (bbb == "y");
}
}