Programming contests

50 Programming Exercise for Beginners

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

Arithmetic Operations #2

Write a program that reads integers and operators of the C programming language from the standard input line by line, performs the operation indicated by the operator on the scanned/read values and writes the result to the standard output.

Input Specification

Each of the input lines contains a test case until end-of-file (EOF). Each test case is a line in the form „x op y” where x and y are integers, while op is one of the following integer arithmetic operators of the C programming language: +, -, *, /, %. The operands are separated from the operator by a space character.

Output Specification

For each test case, the program must write a single line containing the result of the operation x op y specified in the test case.

Sample Input

  1. 5 + -5
  2. 165 - -10
  3. -5 * -2
  4. 23 / 8
  5. 25 % 3
download as text file

Output for Sample Input

  1. 0
  2. 175
  3. 10
  4. 2
  5. 1
download as text file
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