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 read from the standard input and consist of 5 integers, each between -100 and +100.

Input Specification

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.

Sample Input

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

Output Specification

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

Output for Sample Input

  1. 55
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.)

The second sum can be implemented as another iteration or in a function. We recommend to use the second approach, it can help you to keep the code simple.

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. 09/30/2024