Programming contests

50 Programming Exercise for Beginners

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

Arithmetic Operations #3

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

A bemenet sorainak mindegyike egy-egy tesztesetet ír le. Minden teszteset egy „x op y” formátumú sor, ahol x és y egész számok, míg op a C programozási nyelv egész típusú operandusokra alkalmazható alábbi aritmetikai operátorainak egyike: +, -, *, /, %. Az operandusok az operátortól egy-egy szóközzel vannak elválasztva. A beolvasás mindaddig folytatódjon, míg x és y értéke közül egyik sem 0! Az utolsó tesztesetet már nem kell feldolgozni.

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
  6. 6 * 0
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