#include<stdio.h>
// Author- Khadiza Sultana
// 10/8/2024
// Takes a fraction and prints the lowest form of the fraction
int main() {
int a, b, x, y, gcd; // Take two integers as input
printf("Enter the fraction (a/b): ");
scanf("%d/%d", &a, &b);
x = a;
y = b;
// Using Euclidean algorithm to find the GCD of a and b
while (y != 0) {
int remainder = x % y;
x = y;
y = remainder;
}
// x now contains the GCD
gcd = x;
// Dividing both numerator and denominator by GCD to get the reduced fraction
a = a / gcd;
b = b / gcd;
printf("In lowest terms: %d/%d\n", a, b);
return 0;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter