Programming contests

20 Programming Exercise for Beginners

January 1, 2019 12:00 AM – December 31, 2019 12:00 AM

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.

Input Specification

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.

Sample Input

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
download as text file

Output specification

The output consists of one single line containing the evaluation result terminated with a newline character.

Output for Sample Input

  1. 51
download as text file

Hints and Guide

Based on the input definition, an integer (int type) variable is sufficient to store the results of the calculations.

A standard method is to convert the textual input data to integer with the help of the scanf function declared in the standard input-output library.

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