码迷,mamicode.com
首页 > Windows程序 > 详细

Visual Studio-C#-20160413-条件语句练习题

时间:2016-04-13 17:07:33      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:

 

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-条件语句练习题

标签:

原文地址:http://www.cnblogs.com/xcc2016/p/5387797.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!