Write a program that displays the quotient and the remainder of the integer division of two integers entered on the keyboard as well as the rational quotient of those numbers.


Difficulty level
Video recording
This exercise is mostly suitable for students
#include <stdio.h>

int main()
{
    int a ,b ;
    int quotient; 
    
    printf("Please enter 2 integers: ");
    scanf("%d %d", &a, &b);
    
    // version 1 
    printf("Quotient = %d\n" , a/b );
    
    // version 2 
    quotient = a/b;
    printf("Quotient = %d\n" , quotient );
    
    printf("Remainder = %d\n" , a%b );
    
    //  version 1 
    printf("Rational Quotient = %lf\n" , (double) a/b );
    
    //  version 2 
    printf("Rational Quotient = %lf\n" ,  1.0 * a / b );
    
    //  version 1 wrong
    printf("Rational Quotient wrong = %lf\n" , (double) (a/b) );
    
    
    return 0;
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Tracing QuickSort and Heapsort