Evaluation of a Compound Expression
Create a console application that evaluates the following expression.
The input data is served by the standard input and consist of 5 integer between -100 and +100.
The input data is an integer vector with five component. Each value in the vector stays in a single row terminated by a newline character.
The output consists of one single line containing the evaluation result terminated with 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.)
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|