Evaluation of a Compound Expression
Create a console application that evaluates the following expression.
The input data is read from the standard input and consist of 5 integers, each between -100 and +100.
The input consists of an integer vector with five elements. All elements of the vector appear in a single line, which is terminated by a newline character.
The output consists of a single line containing the result of the evaluation terminated by a newline character.
Output for Sample Input
Hints and Guide
Based on the input definition, an integer (
A standard method is to convert the textual input data to integer with the help of the
The easiest way to implement the sums is to create an iteration. To do so we recommend to use array to represent the vector. Do not forget, that the arrays in C, as in many other programming languages, are indexed from 0. If we wish to keep the original indexing model, the easiest way is to declare an array with 6 member so we can use indexes from 1 up to 5. (Note that the first member of the array indexed by 0 exists but useless.)
The evaluation seems to be simple, but it requires double iteration. As in the expression the iterations require they own variables. e.g.,
The output can be done by using the
One possible solution is available in: main.c.
Acknowledgement This work was supported by the construction EFOP-3.4.3-16-2016-00021. The project was supported by the European Union, co-financed by the European Social Fund.
|University of Debrecen; Faculty of Informatics; v. 03/01/2019|