w3resource logo


C Programming Exercises

C Exercises: Find the quotient and remainder of a division

Secondary Nav

C Variable Type : Exercise-10 with Solution

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

Test Data and Expected Output :

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

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;
}

Solution

#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



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

PHP: Loop

JavaScript: Delete duplicates in an array

Oracle: Round the number