none
Write the program to calculate X in equation 3X-20=4; please RRS feed

  • Question

  • using System;
    namespace Class
    {
        class Program
        {
            static void Main(string[] args)
            {
              3x-20=4;

             Console.WriteLine(x);

            }



        }
    }

    Tuesday, October 29, 2019 3:41 PM

Answers

  • Hi pavlob,

    If a given equation "3x-20=4" is fixed, code would be like this:
    x = (4 + 20) / 3;
    Console.WriteLine("x = " + x);
    Console.ReadLine();
    I guess the given equation varies.
    If so, you need to provide requirements about the equation.
    e.g.
      the equation is given by Console.ReadLine.
      an arithmatic operator occurs only once and it is "-".
      Regards,

    Ashidacchi -- http://hokusosha.com

    • Proposed as answer by cheong00Editor Wednesday, October 30, 2019 1:12 AM
    • Marked as answer by Decompressor Wednesday, October 30, 2019 7:09 AM
    Tuesday, October 29, 2019 11:44 PM

All replies

  • Hi pavlob,

    If a given equation "3x-20=4" is fixed, code would be like this:
    x = (4 + 20) / 3;
    Console.WriteLine("x = " + x);
    Console.ReadLine();
    I guess the given equation varies.
    If so, you need to provide requirements about the equation.
    e.g.
      the equation is given by Console.ReadLine.
      an arithmatic operator occurs only once and it is "-".
      Regards,

    Ashidacchi -- http://hokusosha.com

    • Proposed as answer by cheong00Editor Wednesday, October 30, 2019 1:12 AM
    • Marked as answer by Decompressor Wednesday, October 30, 2019 7:09 AM
    Tuesday, October 29, 2019 11:44 PM
  • Hi pavlob, 

    Thank you for posting here.

    If you want to solve polynomial equation, you can refer to the following reference.

    Polynomial Equation Solver

    I download the project and make a test.

    Here’s a result of my test.

    Hope it could be helpful.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by cheong00Editor Wednesday, October 30, 2019 3:49 AM
    Wednesday, October 30, 2019 3:03 AM
    Moderator
  • To Xingyu Zhao: I tried to download your solver, it was error when starting the program in visual studio. Can you put your code here, please?
    Wednesday, October 30, 2019 8:02 AM
  • How to write code, if X is not integer?
    Wednesday, October 30, 2019 8:37 AM
  • Use float, instead of int.
    If int (-2147483648 ~ +2147483648) is not enough, use long.

    # I'm afraid you need to learn Variable and its Type.

    Ashidacchi -- http://hokusosha.com

    Wednesday, October 30, 2019 9:16 AM
  • I've used double, decimal, float, but anyway received int in answer
    Wednesday, October 30, 2019 9:32 AM
  • using static System.Console;
    using static System.Math;
    class Program
    {
        static void Main()
        {
            float x = (3 + 4) / 2;
            WriteLine("x=" + x);
            ReadLine();
        }
    }
    Wednesday, October 30, 2019 9:38 AM
  • I've used double, decimal, float, but anyway received int in answer
    I suppose it is because x is integer.

    How do you want to see "x"?  "8.0", "8.00"....??


    Ashidacchi -- http://hokusosha.com

    Wednesday, October 30, 2019 10:03 AM
  • I want see "x" as 8.00
    Wednesday, October 30, 2019 10:14 AM
  • Please search about "Format" or "ToString".

    Ashidacchi -- http://hokusosha.com

    Wednesday, October 30, 2019 10:45 AM