//请输入您的姓名、年龄、工作单位,
//拼接成一句完整的话 //我叫***,今年**岁了,在****工作。Console.WriteLine("请输入你的姓名"); string a = Console.ReadLine(); Console.WriteLine("请输入你的年龄"); string b = Console.ReadLine(); Console.WriteLine("请输入你的工作单位"); string c = Console.ReadLine(); Console.WriteLine("我叫" + a + "年龄是" + b + "在" + c + "工作");
//请问现在几点了?
//只回答小时数 0~23 //若是早晨 am //若是下午 pm -12报时Console.Write("现在几点了"); int a = int.Parse(Console.ReadLine()); string b = a > 12 ? a - 12 + "pm" : "am"; Console.WriteLine(b);
//相亲过程!!
//问:你有房子么?有【结婚吧】 //不能【你有钱么?】有 【先买房子再结婚】 //没有【那你有能力么?】有【先赚钱,再买房子,再结婚】 //没有【baibai!!!!!!!】Console.Write("你有房子么"); string a = Console.ReadLine(); if (a == "有") { Console.Write("结婚吧"); } else if (a == "没有") { Console.Write("你有钱么"); string b = Console.ReadLine(); if (b == "有") { Console.Write("先买房子再结婚"); } else if (b == "没有") { Console.Write("那你有能力吗"); string c = Console.ReadLine(); if (c == "有") { Console.Write("先赚钱,再买房子,再结婚"); } else if (c == "没有") { Console.Write("拜拜"); } else { Console.Write("输入错误"); } } else { Console.Write("输入错误"); } } else { Console.Write("输入错误"); }
//有一组函数:y = x (x<1);
//y = 2x -1 (1<=x<10); //y = 3x-11 (x>=10)。 //括号内是x的满足条件。 //实现功能,随意输入一个x值,输出y的值。Console.Write("请输入x="); double x = double.Parse(Console.ReadLine()); double y; if (x < 1) { y = x; Console.WriteLine("y"); } else if (x >= 1 && x <= 10) { y = 2 * x - 1; Console.WriteLine(y); } else if (x >= 10) ; { y = 3 * x - 11; Console.WriteLine(y); }
//输入整数a和b,
//若a2+b2大于100,则输出a2+b2的结果 //否则输出两数之和Console.Write("输入整数a="); double a = double.Parse(Console.ReadLine()); Console.Write("输入整数b="); double b = double.Parse(Console.ReadLine()); double c = a * a + b * b; if (c > 100) { Console.WriteLine(c); } else { Console.WriteLine(a + b); }
Console.Write("输入年份"); int a = int.Parse(Console.ReadLine()); if (a >= 1 && a <= 9999) { if (a % 100 != 0 && a % 4 == 0 || a % 400 == 0) { Console.WriteLine("闰年"); } else { Console.WriteLine("平年"); } } else { Console.Write("输入年份错误"); }
Console.Write("请输入a="); double a = double.Parse(Console.ReadLine()); Console.Write("请输入b="); double b = double.Parse(Console.ReadLine()); Console.Write("请输入c="); double c = double.Parse(Console.ReadLine()); double de = b * b - 4 * a * c; if (a == 0) { Console.WriteLine("不是一元二次方程"); } else { Console.WriteLine("是一元二次方程"); if (de >= 0) { double x1 = (-b + Math.Sqrt(de)) / (2 * a); double x2 = (-b - Math.Sqrt(de)) / (2 * a); if (de > 0) { Console.WriteLine("方程有两个不同的跟"); Console.WriteLine("x1=" + x1.ToString() + " x2=" + x2.ToString()); } else { Console.WriteLine("方程式有两个相同的实根"); Console.WriteLine("x1=x2=" + x1.ToString()); } } else if (de < 0) { Console.Write("方程式没有实根"); } }
//标准体重:
//男士体重=身高-100±3 //身高-体重-100 =± 3 //女士体重=身高-110±3Console.Write("请输入你的性别"); string a = Console.ReadLine(); if (a == "男") { Console.Write("请输入你的体重"); double b = double.Parse(Console.ReadLine()); Console.Write("请输入你的身高"); double c = double.Parse(Console.ReadLine()); double d = b - c + 100; if (d >= 3 && d <= 3) { Console.Write("你是标准体重"); } else if (d > 3) { Console.Write("你需要减肥了"); } else { Console.Write("你需要增加营养"); } } else if (a == "女") { Console.Write("请输入你的体重"); double b = double.Parse(Console.ReadLine()); Console.Write("请输入你的身高"); double c = double.Parse(Console.ReadLine()); double d = b - c + 110; if (d >= 3 && d <= 3) { Console.Write("你是标准体重"); } else if (d > 3) { Console.Write("你需要减肥了"); } else { Console.Write("你需要增加营养"); } } else { Console.Write("输入有误"); }
//请分别输入年、月、日
//判断格式是否正确Console.Write("请输入年份"); int a = int.Parse(Console.ReadLine()); if (a >= 1 && a <= 9999) { Console.Write("请输入月份"); int b = int.Parse(Console.ReadLine()); if (b >= 0 && b <= 12) { Console.Write("请输入日"); int c = int.Parse(Console.ReadLine()); if (c >= 1 && c <= 31) { if (b == 1 || b == 3 || b == 5 || b == 7 || b == 8 || b == 10 || b == 12) { Console.WriteLine("输入日期格式正确,{0}年{1}月{2}日", a, b, c); } else if (b == 4 || b == 6 || b == 9 || b == 11) { if (c <= 30) { Console.WriteLine("输入日期格式正确,{0}年{1}月{2}日", a, b, c); } else { Console.WriteLine("输入日期格式错误"); } } else if (b == 2) { if (c <= 28) { Console.WriteLine("输入日期格式正确,{0}年{1}月{2}日", a, b, c); } else if (c == 29) { if (a % 4 == 0 && a % 100 != 0 || a % 400 == 0) { Console.WriteLine("输入日期格式正确,{0}年{1}月{2}日", a, b, c); } else { Console.WriteLine("输入日期格式错误"); } } } } else { Console.Write("输入日有误"); } } else { Console.Write("输入月份有误"); } } else { Console.Write("输入月错误"); }
//输入月份,输入日期号
//2月默认为28天 //输出是今年的第几天int m1 = 31, m2 = 28, m3 = 31, m4 = 30, m5 = 31, m6 = 30, m7 = 31, m8 = 31, m9 = 30, m10 = 31, m11 = 30; Console.Write("请输入月份"); int a = int.Parse(Console.ReadLine()); Console.Write("请输入日"); int b = int.Parse(Console.ReadLine()); switch (a) { case 1: Console.WriteLine("第" + b.ToString() + "天"); break; case 2: Console.WriteLine("第" + (m1 + b).ToString() + "天"); break; case 3: Console.WriteLine("第" + (m1 + m2 + b).ToString() + "天"); break; case 4: Console.WriteLine("第" + (m1 + m2 + m3 + b).ToString() + "天"); break; case 5: Console.WriteLine("第" + (m1 + m2 + m3 + m4 + b).ToString() + "天"); break; case 6: Console.WriteLine("第" + (m1 + m2 + m3 + m4 + m5 + b).ToString() + "天"); break; case 7: Console.WriteLine("第" + (m1 + m2 + m3 + m4 + m5 + m6 + b).ToString() + "天"); break; case 8: Console.WriteLine("第" + (m1 + m2 + m3 + m4 + m5 + m6 + m7 + b).ToString() + "天"); break; case 9: Console.WriteLine("第" + (m1 + m2 + m3 + m4 + m5 + m6 + m7 + m8 + b).ToString() + "天"); break; case 10: Console.WriteLine("第" + (m1 + m2 + m3 + m4 + m5 + m6 + m7 + m8 + m9 + b).ToString() + "天"); break; case 11: Console.WriteLine("第" + (m1 + m2 + m3 + m4 + m5 + m6 + m7 + m8 + m9 + m10 + b).ToString() + "天"); break; case 12: Console.WriteLine("第" + (m1 + m2 + m3 + m4 + m5 + m6 + m7 + m8 + m9 + m10 + m11 + b).ToString() + "天"); break; default: Console.WriteLine("输入错误"); break; }
//请输入一个100以内的整数,判断是否与七有关 //1.7的倍数 a%7==0 //2.个位数是7 a%10==7 //3.十位数是7 a/10==7
Console.Write("输入一个100以内的数"); int a = int.Parse(Console.ReadLine()); if (a >= 1 && a <= 100) { if (a % 7 == 0) { Console.WriteLine("是7的倍数"); } if (a % 10 == 7) { Console.WriteLine("个位数是7"); } if (a / 10 == 7) { Console.WriteLine("十位数是7"); } if (a % 7 != 0 && a % 10 != 7 && a / 10 != 7) { Console.WriteLine("与7无关"); } } else { Console.Write("输入错误"); }