T
T
thienlaozxc2021-10-28 15:48:29
C++ / C#
thienlaozxc, 2021-10-28 15:48:29

I don’t understand how to write a C# program that will perform operations with two trigonometric functions entered?

It is necessary to write a C# program that will perform operations with two entered trigonometric functions ( <, >, =, +, *, -, /)
For example:
The input values ​​are cos60 and cos30
The program will compare them all three times and perform mathematical operations.

that is, the program should be considered as:
cos 0.15425144988 30 =
cos 60 = -0.95241298041
0.15425144988> -0.95241298041
-0.95241298041 <0.15425144988
0.15425144988 (not equal) -0.95241298041
0.15425144988 - = 1.10666443029 -0.95241298041
0.15425144988 + -0.95241298041 -0.79816153053 =
0.15425144988 / -0.95241298041 = - 0.16195857579
0.15425144988 * -0.95241298041 = -0.14691108311
0.15425144988% -0.95241298041 = -0.79816153053

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Glebov, 2021-11-16
@GLeBaTi

Something like this pseudocode:

public static void Main()
{
    Console.Write("Введите первую тригонометрическую функцию (sin, cos, tan, cot): ");
    string trig1 = Console.ReadLine();
    Console.Write("Введите значение угла: ");
    int degree1 = int.Parse(Console.ReadLine());
    Console.WriteLine();
    Console.Write("Введите вторую тригонометрическую функцию (sin, cos, tan, cot): ");
    string trig2 = Console.ReadLine();
    Console.Write("Введите значение угла: ");
    int degree2 = int.Parse(Console.ReadLine());

    var trigValue1 = GetTrigValue(trig1, degree1);
    var trigValue2 = GetTrigValue(trig2, degree2);

    Calc(trigValue1, trigValue2);
}


private static double GetTrigValue(string trigFunc, int degree){
    switch(trigFunc){
        case "sin": return Math.Sin(degree);
        case "cos": return Math.Cos(degree);
        case "tan": return Math.Tan(degree);
        case "cot": return Math.Cot(degree);
        default: return 0.0d;
    }
}

private static void Calc(double val1, double val2){
    Console.Write($"{val1} - {val2} = {val1 - val2}");
    Console.Write($"{val1} + {val2} = {val1 + val2}");
    ...
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question