Visual Studio-C#-20160413-條件陳述式練習題

來源:互聯網
上載者:User

標籤:

 

1.做一個算緣分的小遊戲:
輸入男方姓名,女方姓名,輸出緣分指數,給出建議。

static void Main1342341(string[] args)
{
//男女姓名緣分配對
Console.Write("男方姓名:");
string m = Console.ReadLine();
Console.Write("女方姓名:");
string w = Console.ReadLine();
Random rand = new Random();
int c = rand.Next(100);
Console.WriteLine("兩人的緣份指數為:"+c);
if(c>0&&c<20)
{
Console .WriteLine ("你們倆無緣無份");
}
else if(c>=20&&c<40)
{
Console .WriteLine ("你們倆有緣無份");
}
else if (c >= 40 && c < 60)
{
Console.WriteLine("你們倆相互吸引");
}
else if (c >= 60 && c < 80)
{
Console.WriteLine("你們倆有緣有份");
}
else if (c >= 90 && c < 100)
{
Console.WriteLine("你們倆天生一對");
}
}

 

2.做一個跟電腦猜拳的小遊戲。0-剪刀,1-石頭,2-布
要求輸出0,1,2,電腦產生隨機數,與人類輸入的相比較判斷誰勝了。


static void Main1111112324(string[] args)
{
//與電腦猜拳
Random rand = new Random();
int c = rand.Next(3);
Console .WriteLine ("你選擇0-(剪刀),1-(石頭),2-(布):");
int a=Convert .ToInt32(Console .ReadLine ());
if (c == 0)
{
Console.WriteLine("電腦出的是剪刀!");
if (a == 0)
{
Console.WriteLine("平手!");
}
else if(a == 1)
{
Console.WriteLine("你贏啦!");
}
else if (a == 2)
{
Console.WriteLine("你輸啦!");
}
else
{
Console.WriteLine("輸入錯誤!");
}
}
if (c == 1)
{
Console.WriteLine("電腦出的是石頭!");
if (a == 0)
{
Console.WriteLine("你輸了!");
}
else if (a == 1)
{
Console.WriteLine("平手!");
}
else if (a == 2)
{
Console.WriteLine("你贏啦!");
}
else
{
Console.WriteLine("輸入錯誤!");
}
}
if (c == 2)
{
Console.WriteLine("電腦出的是布!");
if (a == 0)
{
Console.WriteLine("你贏啦!");
}
else if (a == 1)
{
Console.WriteLine("你輸啦!");
}
else if (a == 2)
{
Console.WriteLine("平手!");
}
else
{
Console.WriteLine("輸入錯誤!");
}
}

 


}

 

 

3.男士身高與體重的關係是:身高-100=體重; 女士:身高-110=體重。(自己試著做)
上下浮動3公斤屬正常。
輸入性別,身高,體重,輸出:正常?偏胖?偏瘦?


static void Main3333333333(string[] args)
{
//身高與體重的關係
Console.WriteLine("請輸入性別:");
string s = Console.ReadLine();
Console.WriteLine("請輸入身高cm:");
int t =Convert .ToInt32( Console.ReadLine());
Console.WriteLine("請輸入體重kg:");
int m =Convert .ToInt32( Console.ReadLine());
if (s=="男" )
{
if((t-m)>=97&&(t-m)<=103)
{
Console .WriteLine ("正常");
}
else if((t-m)<97)
{
Console .WriteLine ("偏胖");
}
else
{
Console .WriteLine ("偏瘦");
}
}
else if (s == "女")
{
if ((t - m) >= 107 && (t - m) <= 113)
{
Console.WriteLine("正常");
}
else if ((t - m) < 107)
{
Console.WriteLine("偏胖");
}
else
{
Console.WriteLine("偏瘦");
}
}
else
{
Console.WriteLine("無法辨認性別!");
}

}

 

4.輸入年份,月份,天,判斷這個日期是否正確?

 


static void Main2222(string[] args)
{
//輸入年月日判斷是否正確
Console.WriteLine("輸入年月日:");
int y = Convert.ToInt32(Console.ReadLine());
if (y % 400 == 0 || y % 4 == 0 && y % 100 != 0)
{
int m = Convert.ToInt32(Console.ReadLine());
if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)
{
int d = Convert.ToInt32(Console.ReadLine());
if (d > 0 && d < 32)
{
Console.WriteLine("輸入正確!");
}
else
{
Console.WriteLine("天數輸入錯誤!");
}
}
else if (m == 4 || m == 6 || m == 9 || m == 11)
{
int d = Convert.ToInt32(Console.ReadLine());
if (d > 0 && d < 31)
{
Console.WriteLine("輸入正確!");
}
else
{
Console.WriteLine("天數輸入錯誤!");
}
}
else if (m == 2)
{
int d = Convert.ToInt32(Console.ReadLine());
if (d > 0 && d < 30)
{
Console.WriteLine("輸入正確!");
}
else
{
Console.WriteLine("天數輸入錯誤!");
}
}
else
{
Console.WriteLine("輸入月份錯誤!");
}
}
else
{
int m = Convert.ToInt32(Console.ReadLine());
if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)
{
int d = Convert.ToInt32(Console.ReadLine());
if (d > 0 && d < 32)
{
Console.WriteLine("輸入正確!");
}
else
{
Console.WriteLine("天數輸入錯誤!");
}
}
else if (m == 4 || m == 6 || m == 9 || m == 11)
{
int d = Convert.ToInt32(Console.ReadLine());
if (d > 0 && d < 31)
{
Console.WriteLine("輸入正確!");
}
else
{
Console.WriteLine("天數輸入錯誤!");
}
}
else if (m == 2)
{
int d = Convert.ToInt32(Console.ReadLine());
if (d > 0 && d < 29)
{
Console.WriteLine("輸入正確!");
}
else
{
Console.WriteLine("天數輸入錯誤!");
}
}
else
{
Console.WriteLine("輸入月份錯誤!");
}
}

}



5.輸入年份,月份顯示這個月有多少天?


static void Main33333(string [] args)
{
//輸入年份月份確定該月天數
Console.Write("請輸入年份:");
int year = Convert.ToInt32(Console.ReadLine());
if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0)
{
Console.Write("請輸入月份:");
int m=Convert .ToInt32 (Console .ReadLine ());
if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)
{
Console .WriteLine ("這個月有31天。");
}
else if (m==4||m==6||m==9||m==11)
{
Console .WriteLine ("這個月有30天。");
}
else if (m==2)
{
Console .WriteLine ("這個月有29天。");
}
else
{
Console .WriteLine ("輸入月份錯誤!");
}
}
else
{
Console.Write("請輸入月份:");
int m=Convert .ToInt32 (Console .ReadLine ());
if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)
{
Console .WriteLine ("這個月有31天。");
}
else if (m==4||m==6||m==9||m==11)
{
Console .WriteLine ("這個月有30天。");
}
else if (m==2)
{
Console .WriteLine ("這個月有28天。");
}
else
{
Console .WriteLine ("輸入月份錯誤!");
}
}
}
}
}


6.輸入整點時間自動問好

 

//static void Main11(string[] args)
//{
// //輸入時間問好
// Console.WriteLine("請輸入現在幾點了:");
// int a = Convert.ToInt32(Console.ReadLine());
// if (a >= 0 && a < 6)
// {
// Console.Write("淩晨好!");
// }
// else if (a >= 6 && a < 11)
// {
// Console.Write("上午好!");
// }
// else if (a >= 11 && a < 14)
// {
// Console.Write("中午好!");
// }
// else if (a >= 14 && a < 19)
// {
// Console.Write("下午好!");
// }
// else if (a >= 19 && a < 21)
// {
// Console.Write("晚上好!");
// }
// else if (a >= 21 && a <= 24)
// {
// Console.Write("午夜好!");
// }
// else
// {
// Console.Write("時間輸入錯誤");
// }
//}


7.輸入一個100以內的整數,判斷是否為正整數


//static void Main5(string[] args)
//{
// //輸入一個100以內的數字,判斷是否為正整數
// Console.Write("請輸入數字:");
// int a = Convert.ToInt32(Console.ReadLine());
// if (a > 0 && a <= 100)
// {
// Console.Write("是正整數");
// }
// else
// {
// if(a>100)
// {
// Console .Write ("數字大於100");
// }
// else
// {
// Console .Write ("數字小於1");
// }
// }
//}

 

8.輸入年份判斷是否為閏年

/* static void Main4(string[] args)
{
//判斷輸入的年份是閏年
Console.Write("請輸入年份:");
int year = Convert.ToInt32(Console.ReadLine());
if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0)
{
Console.Write("是閏年");
}
else
Console.Write("是平年");

}


9.比較四個數中的最大值

static void Main3(string[] args)
{
//比較輸入的四個數字中的最大值
Console.WriteLine("請輸入四個數字:");
int a, b, c, d, max;
a=Convert.ToInt32 (Console .ReadLine ());
b=Convert.ToInt32 (Console .ReadLine ());
c=Convert.ToInt32 (Console .ReadLine ());
d=Convert.ToInt32 (Console .ReadLine ());

if (a > b)
{
max = a;
}
else
{
if (b > c)
{
max = b;
}
else
{
if (c > d)
{
max = c;
}
else
{
max = d;
}
}
}
Console.WriteLine(max);
}



10.判斷輸入的兩位元是否與7相關

static void Main2(string[] args)
{
//判斷輸入的兩位元是否與7相關
Console.WriteLine("請輸入一個兩位元:");
int a = Convert.ToInt32(Console .ReadLine ());
if (a % 7 == 0 || a % 10 == 7 || a / 10 == 7)
{
Console.WriteLine("與7相關");
}
else
{
Console.WriteLine("與7無關");
}
}

 

 11.你能跑過豹子嗎?

 

static void Main1(string[] args)
{
//小遊戲你能跑過豹子麼

Console.Write("你能跑過豹子嗎?Y/N");
string a = Convert.ToString(Console.ReadLine());
if (a == "Y"|| a == "y")
{
Console.WriteLine("你比禽獸還禽獸");
}
else
{
Console.WriteLine("你禽獸不如");
}

}*/

Visual Studio-C#-20160413-條件陳述式練習題

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.