• 函数解一元二次方程


    namespace ConsoleApplication10
    {
        class Program
        {
    
            //函数多个返回值、
    
                //输入参数前加out就变成输出参数
            
            public int jiefangcheng(int a, int b , int c,out double x1,out double x2)
            {
                x1 = 0;
                x2 = 0;
                if(0== b*b-4*a*c)
                {
                    x1 = (-b) / (2 * a);
                    x2 = x1;
                    return 1;
                }
    
                else if (0 < b * b - 4 * a * c)
                {
                    x1 = (-b + Math.Sqrt(b * b - 4.0 * a * c)) / (2.0 * a);
                    x2 = (-b - Math.Sqrt(b * b - 4.0 * a * c)) / (2.0 * a);
    
                    return 2;
                }
                   else
    
                {
                    return 0;
                }
            }
            static void Main(string[] args)
            {
                Console.WriteLine("请输入数值a");
                int a = int.Parse(Console.ReadLine());
                Console.WriteLine("请输入数值b");
                int b = int.Parse(Console.ReadLine());
                Console.WriteLine("请输入数值c");
                int c = int.Parse(Console.ReadLine());
    
                double x1, x2;
                int fanhui = new Program().jiefangcheng(a, b, c, out x1, out x2);
    
                if(fanhui ==0)
                {
    
                    Console.WriteLine("两个相等的实数根");
    
                    Console.ReadLine();
                }
            }
        }
    

      

  • 相关阅读:
    codeforce666A_dp
    杭电1789_贪心
    杭电2059_记忆化搜索
    杭电1503_输出最长公共子序列
    杭电1501_dfs和记忆化搜索
    杭电1081_二维dp
    杭电1078_dfs
    coderforce 675C(贪心)
    杭电2571_01背包
    杭电1069_01背包
  • 原文地址:https://www.cnblogs.com/suncan0/p/4990858.html
Copyright © 2020-2023  润新知