Programming contests

50 Programming Exercise for Beginners

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

Arithmetic Operations #1

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

The input contains several test cases. The first line of the input contains a positive integer n indicating the number of test cases. Each of the following lines describes a test case. 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
  2. 5 + -5
  3. 165 - -10
  4. -5 * -2
  5. 23 / 8
  6. 25 % 3
download as text file

Output for Sample Input

  1. 0
  2. 175
  3. 10
  4. 2
  5. 1
download as text file

Possible solutions: main1.c and main2.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