w3resource logo
C Programming Exercises

C Exercises: Find the quotient and remainder of a division

C Variable Type : Exercise-10 with Solution

Write a C program to find the quotient and remainder of a division.

Sample Solution:

C Code:

#include<stdio.h>
#include<stdlib.h>

int main ()
{
    int num1,num2;
	div_t divresult;
	      printf("\n Input numerator : ");
	      scanf("%d",&num1);	
	      printf(" Input denominator : ");
	      scanf("%d",&num2);
	      
	      
	divresult = div (num1,num2);
	printf (" quotient =  %d, remainder = %d.\n\n", divresult.quot, divresult.rem);
	return 0;
}

Sample Output:

Input numerator : 2000                                                                                       
Input denominator : 235                                                                                      
quotient =  8, remainder = 120.

C Programming Code Editor:

#include<stdio.h>
#include<stdlib.h>

int main ()
{
    int num1,num2;
	div_t divresult;
	      printf("\n Input numerator : ");
	      scanf("%d",&num1);	
	      printf(" Input denominator : ");
	      scanf("%d",&num2);
	      
	      
	divresult = div (num1,num2);
	printf (" quotient =  %d, remainder = %d.\n\n", divresult.quot, divresult.rem);
	return 0;
}

Improve this sample solution and post your code through Disqus