Warning
This page is located in archive.

HW 01 - Reducing fractions

Write a simple program that:

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

Hint: 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, and the second is the 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.

Your submission must compile without errors with the following compiler flags

-Wall -Werror -pedantic -std=c99 -O2

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 | ./simplify
1 / 2
Upload your solution into BRUTE as a zip archive containing only the file simplify.c and either a Makefile or readme explaining how to compile it.
courses/be5b99cpl/hw/hw01_-_lab02.txt · Last modified: 2023/10/04 12:24 by brouggeo