Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Printf Fraction The code must be c programming The existing code reads in two in

ID: 641770 • Letter: P

Question

Printf Fraction The code must be c programming

The existing code reads in two integer values representing a numerator and denominator. You should print them as a fraction and the decimal equivalent to 3 decimal places, like this:

Note that formatting is important - numerator and denominator each take up 5 chars of space. The = has a space in front and behind it. The decimal always shows 3 decimal places. Here are more examples with .'s to show padding of the fraction:


Hint: In C you can cast to a double with (double)... OR to do double math with your two ints, multiply by 1.0 to start wirh:

#include <cstdio>
#include <cstring>

int main()
{
    int numerator, denominator;
    scanf("%d %d", &numerator, &denominator);
//Do not modify anything on or above the line below this
//START_PROVIDED

//END_PROVIDED
//Do not modify anything on or below the line above this

}

Explanation / Answer

#include <cstdio>
#include <cstring>

int main()
{
    int numerator, denominator;
    scanf("%d %d", &numerator, &denominator);
//Do not modify anything on or above the line below this

printf("%.3f",(1.0*numerator)/denominator);

//Do not modify anything on or below the line above this

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote