HW 01 - Reducing fractions

Write a simple program that:

  • reads positive integers including zero from the standard input,
  • then simplifies it,
  • and finally prints the simplified fraction to the standard output.

In the case of zero in the numerator, the program prints just zero. When there is zero in the denominator, the program prints Error and returns 1.

Hint: look at the GCD and find an algorithm to compute it.

Some examples of the program behaviour when called as ./main

Standard input Standard output Return value
2 / 4
1 / 2
0
765 / 918
5 / 6
0
101 / 100
101 / 100
0
0 / 78
0
0
99 / 0
Error
1

You can find more testing instances here. Files with the suffix .in contain your input with .out your desired output.

When you have your input in a file, e.g. pub00.in containing

2 / 4
you can pass it to your program in the bash like
$ cat pub00.in | ./main
1 / 2

Upload your solution into BRUTE as a zip archive containing only the file main.c
  • First round of evaluation: 12-13th October 2024
  • Second round of evaluation: after deadline
courses/be5b99cpl/hw/hw01.txt · Last modified: 2024/10/08 16:30 by ulricji1