Thread: converting improper fractions into mixed number

  1. #1
    Registered User
    Join Date
    Oct 2016
    Posts
    18

    converting improper fractions into mixed number

    if (a == 6)
    {


    printf("enter a numerator and a denominator value\n");

    int num, denom,num1;
    int whole = num/denom;
    num1 = num%denom;

    scanf("%d %d", num, denom);
    printf("%d %d/%d", whole, num1, denom);


    This is part of a program I have to write and it isnt working so is there a better way to write it

    The point is to have it write for example: 2 2/4 instead of 10/4

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    It seems you've neglected to call scanf() or something like it to actually get numbers.

    Formula-wise you have things correct, it's just that you need num and denom to be 10 and 4 before you actually divide.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. detab---improper spacing
    By dgoodmaniii in forum C Programming
    Replies: 2
    Last Post: 11-15-2009, 08:15 AM
  2. Improper use of typedef
    By aama100 in forum C++ Programming
    Replies: 3
    Last Post: 01-27-2008, 04:50 PM
  3. improper pointer/ integer combination?
    By pinkpenguin in forum C Programming
    Replies: 4
    Last Post: 11-16-2005, 03:47 PM
  4. converting a hex number to decimal???
    By Unregistered in forum Game Programming
    Replies: 8
    Last Post: 04-13-2002, 05:46 PM
  5. converting string to number
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 04-12-2002, 06:11 AM

Tags for this Thread