w3resource logo


C Programming Exercises

C Exercises: Find the integral quotient and remainder of a division

Secondary Nav

C Variable Type : Exercise-7 with Solution

Write a C program to integral quotient and remainder of a division.

Expected Output :

Input numerator : 2500                                                 
 Input denominator : 235                                                
 quotient =  10, remainder = 150       

C Code:

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

int main ()
{
    long int n,d;
	ldiv_t result;
	
	      printf("\n Input numerator : ");
	      scanf("%ld",&n);	
	      printf(" Input denominator : ");
	      scanf("%ld",&d);		      
	result = ldiv (n,d);
	printf (" quotient =  %ld, remainder = %ld.\n\n",result.quot,result.rem);
	return 0;
}
Expected Output :

Solution


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

int main ()
{
    long int n,d;
	ldiv_t result;
	
	      printf("\n Input numerator : ");
	      scanf("%ld",&n);	
	      printf(" Input denominator : ");
	      scanf("%ld",&d);		      
	result = ldiv (n,d);
	printf (" quotient =  %ld, remainder = %ld.\n\n",result.quot,result.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.