Calculate by successive subtractions the integer quotient and the remainder of the integer division of two integers entered on the keyboard.


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

void main()
{
	int NUM;   /* numerator   of the integer QUOision */
 	int DEN;   /* denominator of the integer QUOision */
 	int QUO;   /* quotient 	  of the integer QUOision */
 	int REM;   /* remainder   of the integer QUOision */

 	printf("Enter the numerator   : ");
 	scanf("%d", &NUM);
 	printf("Enter the denominator : ");
 	scanf("%d", &DEN);

 	REM=NUM;
 	QUO=0;
 	while(REM>=DEN)
    	{
     		REM-=DEN;
     		QUO++;
    	}

	/* or */
	/*
 	for (REM=NUM, QUO=0 ; REM>=DEN ; QUO++)
      		REM-=DEN;
 	*/

 	printf(" %d = %d * %d + %d\n", NUM, DEN, QUO, REM);

	getch();
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Maximum width and depth