练习08随机数应用
using System;
namespace 练习08随机数应用
{
class Program
{
static void Main(string[] args)
{
Random random1 = new Random();
int num = random1.Next(1, 6);
switch (num) {
case 1:
Console.WriteLine("我是第一名");
break;
case 2:
Console.WriteLine("我是第二名");
break;
case 3:
Console.WriteLine("我是第三名");
break;
case 4:
Console.WriteLine("我是第四名");
break;
case 5:
Console.WriteLine("我是第五名");
break;
}
}
}
}
练习09记录班级的总成绩和平均成绩while
using System;
namespace 练习09记录班级的总成绩和平均成绩
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入班级总人数");
int num = Convert.ToInt32(Console.ReadLine());
int count = 1;
int total_score = 0;
while (count <= num) {
Console.WriteLine("请输入成绩");
int score = Convert.ToInt32(Console.ReadLine());
total_score += score;
count += 1;
}
double avg = total_score / num;
Console.WriteLine("学生的平均成绩为{0},总成绩为{1}。", avg, total_score);
}
}
}
练习10水仙花数
using System;
namespace 水仙花数
{
class Program
// 打印0到999所有的水仙花数
{
static void Main(string[] args)
{
for (int i = 0; i <= 999; i++)
{
int ge = i % 10;
int shi = i % 100 / 10;
int bai = i / 100;
if (ge*ge*ge + shi*shi*shi + bai*bai*bai == i)
{
Console.WriteLine(i);
}
}
}
}
}