This page is located in archive. Go to the latest version of this course pages. Go the latest version of this page.

HW 01 - Reducing fractions

Write a simple program that:

  • reads a fraction from the standard input,
  • then simplifies it,
  • and finally prints the simplified fraction to the standard output.

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

Some examples of the program behaviour when called as ./simplify. The first line is the input, the second is output.

$ ./simplify
2 / 4
1 / 2
$ ./simplify
765 / 918
5 / 6
$ ./simplify
101 / 100
101 / 100

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. 1.in containing
768 / 918
you can pass it to your program in the bash like
$ cat in.txt | ./simplify
15 / 18
Upload your solution into BRUTE as a zip archive containing only the file simplify.c with your program. This program will have to be simply compilable by calling clang simplify.c -o simplify.
courses/be5b99cpl/hw/hw01_-_lab02.txt · Last modified: 2022/10/05 11:10 by blahaj22