C# 编一个程序,用while循环语句

编一个程序,用while循环语句,从键盘输入,五个双精度浮点数,求他们中的正数之和,负数之和。( 五个双精度实数 最大数 此最大数)

static void Main(string[] args)
{
double positive = 0;
double negative = 0;
double min = double.MaxValue;
double max = double.MinValue;
int i = 0;
while (i < 5)
{
string value = Console.ReadLine();
double tmp = 0;
if (!double.TryParse(value, out tmp))
{
Console.WriteLine("输入的不是数字!");
}
else
{
if (tmp >= 0)
{
positive += tmp;
}
else
{
negative += tmp;
}
if (tmp > max)
max = tmp;
if (tmp < min)
min = tmp;
i++;
}
}
Console.WriteLine("Sum of all positive number:{0}", positive);
Console.WriteLine("Sum of all negative number:{0}", negative);
Console.WriteLine("Max value is {0}", max);
Console.WriteLine("Min value is {0}", min);
Console.ReadKey();
}
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网