C# 2 闰年平年 老狼几点了

作业

第一题 老狼几点了。凌晨,上午,下午,晚上。

static void Main (string[] args)

{

//输入

Console.Write("老狼老狼几点了?");

string s = Console.ReadLine();

int hour = Convert.ToInt32(s);

if (0 <= hour && hour < 6)

{

Console.WriteLine("凌晨" + hour + "点了");

}

else if (hour >= 6 && hour < 12)

{

Console.WriteLine("上午" + hour + "点了");

}

else if (hour > 12 && hour < 18)

{

hour = hour - 12;

Console.WriteLine("下午" + hour + "点了");

}

else if (hour >= 18 && hour < 24)

{

hour = hour - 12;

Console.WriteLine("晚上" + hour + "点了");

}

else

{

Console.WriteLine("不可识别的时间!");

}

}

//第二题 判断一元二次方程根的情况。

static void Main (string[] args)

{             int a, b, c;            //输入;             Console.Write("请输入系数a:");

a = Convert.ToInt32(Console.ReadLine());

Console.Write("请输入系数b:");

b = Convert.ToInt32(Console.ReadLine());

Console.Write("请输入系数c:");

c = Convert.ToInt32(Console.ReadLine());

//运算输出

if (a == 0)

{

Console.WriteLine("不是一元二次方程");

}

else

{

int d = b * b - 4 * a * c;

if (d > 0)

{

Console.WriteLine("两个不等实根");

}

else if (d == 0)

{

Console.WriteLine("两个相等实根");

}

else

{

Console.WriteLine("无实根");

}

}

}

}

}

//第三题   输入一个年份判断是闰年,还是平年。

static void ccc(string[] args)

{

int year;

//输入

Console.Write("请输入一个年份:");

year = Convert.ToInt32(Console.ReadLine());

//运算

//能被400整除;或能被4整除,但不能被100整除。

if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))

{

Console.WriteLine("是闰年");

}             else

{

Console.WriteLine("是平年");

}

}

}

}

第四题 称体重。

男人的标准体重是:体重(kg)=身高(cm)-100。

女人的标准体重是:体重(kg)=身高(cm)-110。

上下浮动3公斤属正常

要求输入性别、身高和体重,输出正常,偏胖,偏瘦

class Class3

{

static void Main(string[] args)

{

string sex;

int weight, height;

//输入

Console.Write("性别(男,女):");

sex = Console.ReadLine();

Console.Write("身高(CM):");

height = Convert.ToInt32(Console.ReadLine());

Console.Write("体重(KG):");

weight = Convert.ToInt32(Console.ReadLine());

int biaoZhunTiZhong=0;

//运算输出

if(sex == "男")

{

//求标准体重

biaoZhunTiZhong = height - 100;

}

else if(sex == "女")

{

//求标准体重

biaoZhunTiZhong = height - 110;

}

else

{

Console.WriteLine("性别不正确");

}

//求体重差

int tiZhongCha = weight - biaoZhunTiZhong;

if (tiZhongCha >= -3 && tiZhongCha <= 3)

{

Console.WriteLine("体重正常,继续保持!");

}

else if (tiZhongCha < -3)

{

Console.WriteLine("偏瘦,注意增加营养");

}

else

{

Console.WriteLine("偏胖,注意运动减肥");

}

}

}

}

第五题 输入年、月、日,判断是否是个正确的日期。

class Class4

{

static void Main(string[] args)

{

int year = 0, month = 0, day = 0;

//输入

Console.Write("请输入年:");

year = Convert.ToInt32(Console.ReadLine());

Console.Write("请输入月:");

month = Convert.ToInt32(Console.ReadLine());

Console.Write("请输入日:");

day = Convert.ToInt32(Console.ReadLine());

//判断运算输出

//判断年份是否正确

if(year < 0 || year>9999)

{

Console.WriteLine("年输入不正确");

}

else

{

Console.WriteLine("年正确");

}

//判断月份是否正确

if (month < 1 || month > 12)

{

Console.WriteLine("月输入不正确");

}

else

{

Console.WriteLine("月正确");

}

//判断天是否正确

if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)

{

if(day < 1 || day>31)

{

Console.WriteLine("天输入错误,大月份最多是31天");

}

else

{

Console.WriteLine("天正确");

}

}

else if (month == 4 || month == 6 || month == 9 || month == 11)

{

if (day < 1 || day > 30)

{

Console.WriteLine("天输入错误,小月份最多是30天");

}

else

{

Console.WriteLine("天正确");

}

}

else if(month == 2)

{

//闰年与平年的判断

if(year%400==0 || year%4==0&&year%100!=0)

{

//闰年

if (day < 1 || day > 29)

{

Console.WriteLine("天输入错误,闰年2月份最多是29天");

}

else

{

Console.WriteLine("天正确");

}

}

else

{

//平年

if (day < 1 || day > 28)

{

Console.WriteLine("天输入错误,平年2月份最多是28天");

}

else

{

Console.WriteLine("天正确");

}

}

}

}

}

}

时间: 2024-08-07 04:51:01

C# 2 闰年平年 老狼几点了的相关文章

闰年平年

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 闰年平年 { class Program { static void Main(string[] args) { Console.WriteLine("闰年平年查询"); int a = int.Parse(Console.ReadLine()); int iTest = a % 4; switc

for循环①护栏长度 ②广场砖面积 ③判断闰年平年

// static void Main(string[] args)        { const double PI = 3.14; const int BAR_UNIT_PRICE = 25; const int BRICK_UNIT_PRICE = 85; //输入 int a, b; Console.Write("请输入泳池半径:"); string s1 = Console.ReadLine(); a = Convert.ToInt32(s1); Console.Write(

闰年与平年问题

很小白的一个问题,不过做题目常常遇到,还经常给忘了.写下来以备忘了直接过来看下: 闰年平年的区别: 闰年366天 平年365天 多的那一天就是2月的一天,平年二月28天,闰年29天 闰年的判断方式: ①:能被4整除,但不能被100整除 ②:能被400整除,但不能被3200整除 C语言表达: if((year%4==0&&year%100!=0)||(year%400==0)) return true; 附:一年各个月有几天 1.3.5.7.8.10.12月份,每个月31天. 2月闰年有29

程序第二课,运算符

运算符1 算数运算符+- */ % (取余数) 取余数运算的应用场景 奇偶数的区分 把数变化到某个范围之内--彩票生成 能否整除--闰年 平年的问题. ++(自增运算) --(自减运算)--它只能对变量进行运算 int a=5;a++:a=a+1//7++//错误CONSOLE WRITELINE(a);//a=6前自增 前自检 :先进行自增.自检运算 然后再进行其他运算,可以简单认为前自增前自检 优先级是最高的 b=++sint a=5,b;b=++aconsole.writeline("a&

js日历

1 <html> 2 <head> 3 <title>日历表格</title> 4 <style type="text/css"> 5 .DateTime { 6 width: 99%; 7 margin-top: 4px; 8 } 9 .dateTitle { 10 text-align: center; 11 } 12 ul li { 13 list-style: none; 14 float: left; 15 widt

C#变量/数据类型转换/运算符使用

1.变量 命名规则: a 只能是字母(a-z),数字(0-9),下划线(_)b 不能用数字开头c 不能是C#中的关键字 命名规范: a 简短,有语义的单词或组合b 骆驼命名法(从第二个单词开始,首字母大写)myName 使用步骤: a 声明并赋值(例:int age=18)b 使用(输入输出.判断.运算等...)* 先赋值再使用 2.数据类型 整形和非整形:整形:sbyte(有符号的-128~127) byte(0~255 )一个字节8位short(-32768~32767)ushort(0~6

oracle 时间函数

加法 select sysdate,add_months(sysdate,12) from dual; --加1年 select sysdate,add_months(sysdate,1) from dual; --加1月 select sysdate,to_char(sysdate+7,'yyyy-mm-dd HH24:MI:SS') from dual; --加1星期 select sysdate,to_char(sysdate+1,'yyyy-mm-dd HH24:MI:SS') from

002.变量、类型转换、运算符

1.变量 命名规则: a 只能是字母(a-z),数字(0-9),下划线(_)b 不能用数字开头c 不能是C#中的关键字 命名规范: a 简短,有语义的单词或组合b 骆驼命名法(从第二个单词开始,首字母大写)myName 使用步骤: a 声明并赋值(例:int age=18)b 使用(输入输出.判断.运算等...)* 先赋值再使用 2.数据类型 整形和非整形:整形:sbyte(有符号的-128~127) byte(0~255 )一个字节8位short(-32768~32767)ushort(0~6

java 实现打印当前月份的日历

实现当前日历的打印,当前日期用*来表示. 关键得出这个月的第一天是星期几. 基姆拉尔森计算公式 W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7 在公式中d表示日期中的日数+1,m表示月份数,y表示年数. 注意1:在公式中有个与其他公式不同的地方: 把一月和二月看成是上一年的十三月和十四月, 例:如果是2004-1-10则换算成:2003-13-10来代入公式计算. 注意2:在大多数天主教国家的日历中,在1752年没有9.3-9.13,在这一年的日历中9月