Add Fractions
eharetea

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_numf_dens_nums_dennumdendivisorreduced;
    
    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 50divisor 1divisor--)
    {
        if (( den%divisor == ) && (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_numf_dens_nums_den, (f_num s_den) + (s_num f_den), f_den s_dennumden);
    } else {    
        printf("%d/%d + %d/%d = %d/%d"f_numf_dens_nums_dennumden);
    }


    return 0;
}



Downloads:
Download: file.c 918 B

Please login or Click Here to register for downloads
Creative Commons License
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