w3resource

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

C Variable Type : Exercise-7 with Solution

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

Sample Solution:

C Code:

#include<stdio.h>      // Include the standard input/output header file.
#include<stdlib.h>     // Include the standard library header file.

int main ()          // Start of the main function.
{
long int n, d;    // Declare two long integer variables 'n' and 'd'.
ldiv_t result;    // Declare a variable of type ldiv_t to store the result of the division.

printf("\n Input numerator : ");   // Prompt the user to input the numerator.
scanf("%ld",&n);   // Read the user's input and store it in 'n'.

printf(" Input denominator : ");   // Prompt the user to input the denominator.
scanf("%ld",&d);   // Read the user's input and store it in 'd'.

result = ldiv (n,d);   // Perform the division using the ldiv function and store the result in 'result'.

printf (" quotient =  %ld, remainder = %ld.\n\n",result.quot,result.rem);   // Print the quotient and remainder.

return 0;   // Return 0 to indicate successful execution of the program.
}   // End of the main function.

Sample Output:

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

Flowchart:

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

C Programming Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a C program to sort the elements of an array.
Next: Write a C program to return the absolute value of a long integer.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/c-programming-exercises/variable-type/c-variable-type-exercises-7.php