題目
不斷要求使用戶輸入一個數(shù)字(假定用戶輸入的都是正整數(shù))
當用戶輸入end的時候顯示剛才輸入的數(shù)字中的最大的值
代碼
string strnum; //儲存用戶輸入的字符
int max = 0; //儲存最大值
do
{
Console.WriteLine("請輸入一個數(shù)");
strnum = Console.ReadLine();
if (strnum != "end") //判斷輸入是否為end
{
int num = Convert.ToInt32(strnum);
if (max < num) //將最大值與輸入值比較
{
max = num;
}
}
} while (strnum != "end");
Console.WriteLine("最大的數(shù)為{0}", max);
Console.ReadKey();
效果圖

image.png