Thread: help with reduced fractions

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    1

    help with reduced fractions

    #include <stdio.h>
    /* any other #includes you think you need */

    void inputFraction(int *numerator, int *denominator);
    /* Prompts for and inputs a fraction with input verification */

    void reduceFraction(int *numerator, int *denominator);
    /* Modifies the fraction so that it is in reduced form */

    void printReducedFraction(int numerator, int denominator);
    /* Prints the reduced fraction numerator/denominator with appropriate message
    Calls reduceFraction
    */


    int gcd(int x, int y)
    {
    if ( x % y == 0)
    return y;
    return gcd(y,x%y);
    }

    /* Do not modify the main function */
    int main()
    {
    int num, denom;
    char response;
    printf("\nThis function inputs fractions and prints the equivalent fraction in reduced form.\n\n");
    do {
    inputFraction(&num, &denom);
    printf("\n");
    printReducedFraction(num,denom);

    /* First clear the buffer, especially of any residual newline! */
    while (getchar() != '\n');

    printf("\nDo you wish to process another fraction (Y for yes, N for no):");

    response = getchar();
    printf("\n");
    } while (toupper(response) == 'Y');

    return 0;
    }

    /* You must supply the definitions of the functions above main except for gcd */

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > /* You must supply the definitions of the functions above main except for gcd */
    Well it looks like you sailed straight past << !! Posting Code? Read this First !! >> and dumped your tutor's code on the board.

    Where is your ACTUAL effort, which is more than ctrl-a, ctrl-c, ctrl-v and "submit"?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fractions
    By zdream8 in forum C Programming
    Replies: 2
    Last Post: 05-21-2008, 09:54 PM
  2. Algebraic Fractions
    By treenef in forum C++ Programming
    Replies: 8
    Last Post: 12-20-2005, 05:10 AM
  3. Greatest Common Factors of Fractions
    By sonict in forum C++ Programming
    Replies: 1
    Last Post: 01-15-2003, 04:33 AM
  4. Fractions
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2002, 07:51 AM
  5. Decimals to Fractions
    By ToasterPas in forum C++ Programming
    Replies: 4
    Last Post: 12-28-2001, 12:58 PM