1、方程ax^2+bx+c=0;一元二次方程。求根
△=b^2-4ac;若△<0方程无实根
若△>0,方程有两个不相同的实根x1 x2
若△=0,方程有两个相同的实根
Console.WriteLine("求方程式:a*x*x+b*x+c=0");
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());
if (a == 0)
{
Console.WriteLine("该方程不是一元二次方程。");
}
else
{
Console.WriteLine("该方程是一元二次方程");
if (b * b - 4 * a * c >= 0)
{
double x1 = (-b + Math.Sqrt(b * b - 4 * a * c)) / (2 * a);
double x2 = (-b - Math.Sqrt(b * b - 4 * a * c)) / (2 * a);
if (b * b - 4 * a * c > 0)
{
Console.WriteLine("该方程有两个不等的实根:");
Console.WriteLine("x1=" + x1.ToString() + "x2=" + x2.ToString());
}
else
{
Console.WriteLine("该方程有两个相等的实根:");
Console.WriteLine("x1=x2=" + x1.ToString());
}
}
else
{
Console.WriteLine("该方程没有实根");
}
}
Console.ReadLine();
2、有一组函数:
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 y1 = x;
double y2 = 2 * x - 1;
double y3 = 3 * x - 11;
if (x < 1)
{
Console.WriteLine("y=x");
Console.WriteLine("方程的解:y="+y1);
}
else if (x >= 1 && x < 10)
{
Console.WriteLine("y=2*x-1");
Console.WriteLine("方程的解:y="+y2);
}
else
{
Console.WriteLine("y=3*x-11");
Console.WriteLine("方程的解:y="+y3);
}
Console.ReadLine();
3、输入整数a和b,若a^2+b^2大于100,
则输出a^2+b^2百位以上数字,否则输出两数之和
Console.Write("输入整数a=");
int a = int.Parse(Console.ReadLine());
Console.Write("输入整数b=");
int b = int.Parse(Console.ReadLine());
int jihe = a * a + b * b;
int he = a + b;
if (jihe > 100)
{
Console.WriteLine("a^2+b^2=" + jihe);
}
else
{
Console.WriteLine("a+b=" + he);
}
Console.ReadLine();
4、相亲过程:你有房子么?你有钱么?你有能力么?
【结婚吧】【先买房子再结婚】【先赚钱再买房子再结婚】都没有【拜拜~~】
利用if嵌套做相亲过程
Console.Write("你有房子吗?");
string a = Console.ReadLine();
if (a == "有" || a == "嗯")
{
Console.WriteLine("我们结婚吧!");
}
else
{
Console.Write("你有存款吗?");
string b = Console.ReadLine();
if (b == "有" || b == "嗯")
{
Console.WriteLine("先买房子再结婚吧!");
}
else
{
Console.Write("你有能力吗?");
string c = Console.ReadLine();
if (c == "有" || c == "嗯")
{
Console.WriteLine("先赚钱买房子再结婚!");
}
else
{
Console.WriteLine("拜拜~");
}
}
}
Console.ReadLine();
5、输入月份 几号 ,输出是今年的第多少天?
1 3 5 7 8 10 12 为31天
4 6 9 11 为30天
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 m = int.Parse(Console.ReadLine());
Console.Write("请输入几号:");
int d = int.Parse(Console.ReadLine());
switch (m)
{
case 1:
Console.WriteLine("第"+d.ToString()+"天");
break;
case 2:
Console.WriteLine("第" +( m1+d ).ToString()+ "天");
break;
case 3:
Console.WriteLine("第" + (m1 +m2+ d).ToString() + "天");
break;
case 4:
Console.WriteLine("第" + (m1 + m2 +m3+ d).ToString() + "天");
break;
case 5:
Console.WriteLine("第" + (m1 + m2 + m3 +m4+ d).ToString() + "天");
break;
case 6:
Console.WriteLine("第" + (m1 + m2 + m3 + m4 +m5+ d).ToString() + "天");
break;
case 7:
Console.WriteLine("第" + (m1 + m2 + m3 + m4 + m5 +m6+ d).ToString() + "天");
break;
case 8:
Console.WriteLine("第" + (m1 + m2 + m3 + m4 + m5 + m6 +m7+ d).ToString() + "天");
break;
case 9:
Console.WriteLine("第" + (m1 + m2 + m3 + m4 + m5 + m6 + m7+m8+d).ToString() + "天");
break;
case 10:
Console.WriteLine("第" + (m1 + m2 + m3 + m4 + m5 + m6 + m7 + m8 +m9+ d).ToString() + "天");
break;
case 11:
Console.WriteLine("第" + (m1 + m2 + m3 + m4 + m5 + m6 + m7 + m8 + m9 +m10+ d).ToString() + "天");
break;
case 12:
Console.WriteLine("第" + (m1 + m2 + m3 + m4 + m5 + m6 + m7 + m8 + m9 + m10 +m11+ d).ToString ()+ "天");
break;
default:
Console.WriteLine("您输入有误!");
break;
}
Console.ReadLine();