C#第四节课

分值语句(1)

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace fenzhiyuju1
{
class Program
{
static void Main(string[] args)
{
//语句分类:顺序语句,选择语句(分支语句),循环语句
//选择、分支语句
//if(){}
//int a = 10;
//if (a < 10) {
// a++;

//}
//if(a>3){
// a--;
//}
//Console.WriteLine(a);


//if(){}else{}
//若if成立,只走if不走else
//若if不成立,则走else不走if
//int a = 10;
//if (a > 3)
//{
// a--;
//}
//else
//{
// a++;
//}
//Console.WriteLine(a);

//if(){}else if(){}else if(){}else{} 多选一
//若if不成立,去查看下一个else if成立不成立,若成立,剩下的就不执行了,若不成立继续向下运行
//int a = 10;
//if(a>12)
//{
// a++;
//}
//else if (a < 3)
//{
// a++;
//}
//else
//{
// a++;
//}


//if的嵌套
//if()
//{
// if()
// {
//
// }
// else
// {
// }
// }
//int a = 10;
//if (a < 100)
//{
// if (a > 3 && a < 20)
// {
// a++;
// }
//}
//else
//{
// a--;
//}

//联系
//输入一个小于等于100的整数,判断:
//是小于10的
//两位数
//是100
//Console.Write("请输入一个小于等于100的整数:");
//int a = int.Parse(Console.ReadLine());
//if (a <= 100)
//{
// if (a < 10)
// {
// Console.WriteLine("您输入的是一个小于10的数");
// }
// else if (a < 100)
// {
// Console.WriteLine("您输入的是一个两位数");
// }
// else
// {
// Console.WriteLine("您输入的是100");
// }
//}
//else
//{
// Console.WriteLine("您输入的有误");
//}
//输入三个整数,xyz,最终以从小到大的方式输出。
//利用嵌套。
for (; ; )
{
// Console.WriteLine("请输入X:");
// double X = double.Parse(Console.ReadLine());
// Console.WriteLine("请输入Y:");
// double Y = double.Parse(Console.ReadLine());
// Console.WriteLine("请输入Z:");
// double Z = double.Parse(Console.ReadLine());

//if (X > Y)
//{
// if (X > Z)
// {
// if (Y > Z)
// {
// Console.WriteLine("Z<Y<X");
// }
// else
// {
// Console.WriteLine("Y<Z<X");
// }
// }
// else
// {
// Console.WriteLine("Y<X<Z");
// }
//}
//else if (X > Z)
//{
// Console.WriteLine("Z<X<Y");
//}
//else
//{
// if (Z > Y)
// {
// Console.WriteLine("X<Y<Z");
// }
// else
// {
// Console.WriteLine("X<Z<Y");
// }
//}

//输入两个数,将a的值给b,将b的值给a
//中间变量
//int a = 2;
//int b = 5;
//int zhong = a;
//a = b;
//b = zhong;


//输入三个整数,xyz,最终以从小到大的方式输出。
//Console.WriteLine(x);
//Console.WriteLine(y);
//Console.WriteLine(z);
//利用中间变量
// double a = X;
// if (X < Y && X < Z)
// {
// if(Y>Z)
// {
// a = Z;
// Z = Y;
// Y = a;
// }
// }
// else if (Y < X && Y < Z)
// {
// if (X > Z)
// {
// X = Y;
// Y = Z;
// Z = a;
// }
// else
// {
// X = Y;
// Y = a;
// }
// }
// else
// {
// if (X > Y)
// {
// X = Z;
// Z = a;
// }
// else
// {
// X = Z;
// Z = Y;
// Y = a;
// }
// }

 

// Console.WriteLine("输出顺序为:");
// Console.WriteLine(X);
// Console.WriteLine(Y);
// Console.WriteLine(Z);

//Console.WriteLine("你好,请问你有房吗?");
//string a = Console.ReadLine();
//if (a == "有"||a=="有啊"||a=="当然有"||a=="必须的"||a=="废话"||a=="肯定有"||a=="肯定有啊"||a=="有有有"||a=="必须有啊")
//{
// Console.WriteLine("那咱们结婚吧!");
// Console.WriteLine("好,换下一个");
//}
//else
//{
// Console.WriteLine("那,你有存款吗?");
// string b = Console.ReadLine();
// if (b == "有" || b == "有啊" || b == "当然有" || b == "必须的" || b == "废话" || b == "肯定有" || b == "肯定有啊" || b == "有有有"||b=="必须有啊")
// {
// Console.WriteLine("那你先拿存款买了房,咱们再结婚吧。。");
// Console.WriteLine("好,换下一个");
// }
// else
// {
// Console.WriteLine("呃。。。那。。。你有能力吗。。。。。。");
// string c = Console.ReadLine();
// if (c == "有" || c == "有啊" || c == "当然有" || c == "必须的" || c == "废话" || c == "肯定有" || c == "肯定有啊" || c == "有有有"||c=="必须有啊")
// {
// Console.WriteLine("好吧。。你先凭能力挣钱,然后有钱买了房子,咱们再说结婚的事吧.....");
// Console.WriteLine("好,换下一个");
// }
// else
// {
// Console.WriteLine("呵呵哒,拜拜吧~");
// Console.WriteLine("好,换下一个");
// }
// }
//}

//输入学生姓名,输入考试成绩 double
//若是100,【恭喜你***,满分通过!】
//若是大于80小于100,【】
//若是大于60小于80

 

//Console.WriteLine("请输入名字");
//string a = Console.ReadLine();
//Console.WriteLine("请输入分数");
//double b = double.Parse(Console.ReadLine());
//if(b==100)
//{
// Console.WriteLine("恭喜你" + a + "满分通过");
//}else if(b>80&&b<100)
//{
// Console.WriteLine(a+"你很优秀,继续保持!");
//}
//else if (b > 60 && b < 100)
//{
// Console.WriteLine(a+",成绩良好!");
//}
//else if (b > 50 && b < 100)
//{
// Console.WriteLine(a+"就差一点就能及格,下次努力");
//}
//else if (b >= 0 && b < 100)
//{
// Console.WriteLine(a+"!!你是笨蛋么???");
//}
//else
//{
// Console.WriteLine("输入有误");
//}

//有一组函数:y=x (x<1);
//y=2x-1 (1<=x<10);
//y=3x-11 (x>=10).
//括号内是x的满足条件
//实现功能,随意输入一个x值,输出x值。
//Console.WriteLine("请输入x的值:");
//double x = double.Parse(Console.ReadLine());
//double y ;
//if (x < 1)
//{
// y = x;
//}else if(x>=1&&x<10)
//{
// y = (2 * x - 1);
//}
//else
//{
// y = (3 * x - 11);
//}


//Console.WriteLine(y);

double x;
double y;
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("这个不是一元二次方程");
if (b == 0 && c == 0)
{
Console.WriteLine("方程组有无数解");
}
else if (b == 0)
{
Console.WriteLine("方程组无解");
}
else if (c == 0)
{
Console.WriteLine("有唯一解x=0");
}
else
{
Console.WriteLine("有唯一解x="+(c/b));
}
}else
{
Console.WriteLine("这个是一元二次方程");
y=(b*b-4*a*c);
if (y > 0)
{
Console.WriteLine("有两个根x=" + ((-b + Math.Sqrt(y)) / (2 * a)) + "和" + ((-b - Math.Sqrt(y)) / (2 * a)));
}
else if (y == 0)
{
Console.WriteLine("有一个根x=" + (-b / (2 * a)));
}
else
{
Console.WriteLine("x没有实根");
}
}

 

 

 

 

 

}

 

 


Console.WriteLine();
}
}
}

posted @ 2016-03-07 11:07  熊小白  阅读(153)  评论(0编辑  收藏  举报