Adds two fractions, and reduces them using the modulus function.
Add fractions in C.
Date Created:Tuesday March 06th, 2007 01:52 PM
Date Modified:Saturday August 02nd, 2008 03:14 PM
#include <stdio.h>
int main()
{
int f_num, f_den, s_num, s_den, num, den, divisor, reduced;
printf("First Fraction-->\nEnter the numerator:\n");
scanf("%d", &f_num);
printf("Enter the denominator:\n");
scanf("%d", &f_den);
printf("Second Fraction-->\nEnter the numerator:\n");
scanf("%d", &s_num);
printf("Enter the denominator:\n");
scanf("%d", &s_den);
den = f_den * s_den;
num = (f_num * s_den) + (s_num * f_den);
for ( divisor = 50; divisor > 1; divisor--)
{
if (( den%divisor == 0 ) && (num%divisor == 0))
{
den /= divisor;
num /= divisor;
reduced = 1;
}
}
if (reduced ==1) {
printf("%d/%d + %d/%d = %d/%d, which reduces to %d/%d", f_num, f_den, s_num, s_den, (f_num * s_den) + (s_num * f_den), f_den * s_den, num, den);
} else {
printf("%d/%d + %d/%d = %d/%d", f_num, f_den, s_num, s_den, num, den);
}
return 0;
}
Downloads:
Download: file.c 918 B
Please login or Click Here to register for downloads
Add Fractions by Dan Lynch
is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Based on a work at www.3daet.com
Permissions beyond the scope of this license may be available at http://www.3daet.com
