Rules for writing arithmetic expressions in a programming language
Suppose we need to evaluate an expression written in mathematical form in the following way:
Before writing a program that calculates the result for us, we formulate rules recordings of algebraic expressions in a programming language:
1. Expressions contain numbers, other variable names, operation signs, parentheses, function names.< br />
2. Arithmetic operations and their signs (+, -, *, /, % em>).
3. The separator between integer and fractional parts is a dot.
4. The expression is written one per line (linear notation of expressions), the characters are sequentially lined up one after another, all operation signs are put down; parentheses are used.
Thus, following the rules for writing arithmetic expressions, we must translate this (mathematical notation) fraction into a linear notation, that is, write the fraction in one line.
The numerator and denominator contain complex (that is, they contain two or more factors) expressions, then when writing in a linear form, you need parenthesize expressions in the numerator and denominator.
Thus, the linear notation of such an expression would look like this:
(2*17.56*17.56)/(7*2.47*0.43)
Let's write a program to calculate this expression: to do this, let's define the input and output data.
input data: all values are known, so there is no need to enter anything from the keyboard, therefore, there will be no input data.
output data: the program should display the result of the given arithmetic expression (you can enter it into any variable, or immediately display the value on the screen).
We will immediately display the result of the expression on the screen without saving it in any variable.
The result will be a real number.
using System;
class Program {
static void Main(){
Console.WriteLine((2 * 17.56 * 17.56) / (7 * 2.47 * 0.43));
}
}
Run the program on your computer and make sure it outputs 82.949843. em>