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

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("你禽兽不如");
}

}*/

时间: 2024-08-29 04:27:55

Visual Studio-C#-20160413-条件语句练习题的相关文章

if while 条件语句练习题

1.使用while循环输入123456 8910 n = 1 while n < 11 if n == 7 pass else print(n) n= n + 1 2.求1-100内所有数的和. n = 1 s = 0 while n < 101 s= s + n n= n + 1 print(s) 3.输出1-100内所有的奇数 n = 1 while n < 101 temp = n % 2 if temp == 0 pass else print(n) n= n + 1 4.输出1

if条件语句练习题

习题一: 做一个算缘分的小游戏:输入男方姓名,女方姓名,输出缘分指数,给出建议. static void Main(string[] args) { //做一个算缘分的小游戏: //输入男方姓名,女方姓名,输出缘分指数,给出建议. Console.WriteLine("男方姓名:"); string nan = Console.ReadLine(); Console.WriteLine("女方姓名:"); string nv = Console.ReadLine()

java条件语句练习题

输入三个数字显示最大的: System.out.println("请输入三个数字:"); int a,b,c; Scanner d = new Scanner(System.in); a= Integer.parseInt(d.nextLine()); b= Integer.parseInt(d.nextLine()); c= Integer.parseInt(d.nextLine()); if(a>b&&a>c){ System.out.println(a

Visual Studio 2015 的安装与使用

为什么要使用Visual Studio 2015? 它是中文的.界面友好.自动补全.实时语法错误提示(上图中波浪线部分).单步调试--最重要的社区版是免费的!所以你不必再昧着良心使用不合法.老旧的不兼容当代系统的VC++6.0,Come to VS2015 and enjoy it! 接下来我将告诉你如何安装以及使用它编写.运行C/C++程序! ? 获得Visual Studio 2015 进入Visual Studio 官方网站,点击"下载Visual Studio社区". 如果一切

Visual Studio 2017 发布

https://www.visualstudio.com/zh-cn/news/releasenotes/vs2017-relnotes 发布日期:2017 年 3 月 7 日 摘要 开发:快速导航.编写并修复代码 新的安装体验 - 降低了最小内存需求量以实现更快.更定制化的安装,并且支持脱机安装. Visual Studio IDE - 大幅改进了 Visual Studio 2017,包括减少启动和解决方案加载时间.改进登录和标识.改进代码导航以及增添打开文件视图和链接的服务,实现了应用和任

visual studio 2013 快捷键大全、VS2013常用快捷键

Visual Studio 2013 是一个基本完整的开发工具集,它包括了整个软件生命周期中所需要的大部分工具,如UML工具.代码管控工具.集成开发环境(IDE)等等.VS 2013 中新增了很多提高开发人员工作效率的新功能,比如自动补全方括号.使用快捷键移动整行或整块的代码等: 合理使用快捷键可以提高开发效率.但是Visual Studio提供的快捷键多如牛毛,那我们有没有必要掌握所有快捷键的使用方法呢,答案因人而异.就我个人而言,在开发过程中,我就只用到了其中的很少一部分,但是工作同样进行的

VS2015--win32工程配置的一些想法之在 Visual Studio 2015 中进行调试的同时分析性能

出处: https://msdn.microsoft.com/zh-cn/magazine/dn973013(en-us).aspx 许多开发商花了绝大多数时间获取应用程序才能正常发挥作用.更少的时间里专注于应用程序的性能.虽然有了很长一段时间分析工具在 Visual Studio 中的,他们是单独的一组学习工具.许多开发人员没有花时间去学习和使用它们的时候会出现性能问题. 这篇文章将介绍 Visual Studio 2015 年新的诊断工具调试器窗口. 它还将描述如何使用它来分析性能作为定期调

Visual Studio调试之断点进阶篇

Visual Studio调试之断点进阶篇 在上一篇文章Visual Studio调试之断点基础篇里面介绍了什么是断点,INT 是Intel系列CPU的一个指令,可以让程序产生一个中断或者异常.程序中如果有中断或者异常发生了以后,CPU会中断程序的执行,去一个叫做IDT的部件查找处理这个中断(或者异常)的例程(Handler).IDT是操作系统在启动的时候初始化的,至于IDT的细节问题,例如什么是IDT,怎样编写一个IDT的例程,怎样 初始化IDT,可以去网上搜索一些资料. 总之,这里我们只要知

【MVC 4】4.MVC 基本工具(Visual Studio 的单元测试、使用Moq)

 作者:[美]Adam Freeman      来源:<精通ASP.NET MVC 4> 3.Visual Studio 的单元测试 有很多.NET单元测试包,其中很多是开源和免费的.本文打算使用 Visual Studio 附带的内建单元测试支持,但其他一些.NET单元测试包也是可用的. 为了演示Visual Studio的单元测试支持,本例打算对示例项目添加一个 IDiscountHelper 接口的新实现. 在 Models 文件夹下新建类文件 MinimumDiscountHelpe

有感 Visual Studio 2015 RTM 简介 - 八年后回归 Dot Net,终于迎来了 Mvc 时代,盼走了 Web 窗体时代

有感 Visual Studio 2015 RTM 简介 - 八年后回归 Dot Net,终于迎来了 Mvc 时代,盼走了 Web 窗体时代 太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS.Android.Html5.Arduino.pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作. 关于