Algorithm


1. Accept user input:

- Prompts the user to enter the dividend and divisor.
- Uses scanf to read the input values.

2. Calculate quotient and remainder:
- Computes the quotient by dividing the dividend by the divisor.
- Computes the remainder using the modulus operator.

3. Display results:
- Prints the calculated quotient using printf.
- Prints the calculated remainder using printf.

4. Return statement:
- Returns 0 to indicate successful program execution.

Code Examples

#1 Example- Program to Compute Quotient and Remainder

Code - C Programming

#include <stdio.h>
int main() {
    int dividend, divisor, quotient, remainder;
    printf("Enter dividend: ");
    scanf("%d", ÷nd);
    printf("Enter divisor: ");
    scanf("%d", &divisor);

    // Computes quotient
    quotient = dividend / divisor;

    // Computes remainder
    remainder = dividend % divisor;

    printf("Quotient = %d\n", quotient);
    printf("Remainder = %d", remainder);
    return 0;
}
Copy The Code & Try With Live Editor

Output

x
+
cmd
Enter dividend: 25
Enter divisor: 4
Quotient = 6
Remainder = 1

#2 Example- Using Division and Modulo Operator

Code - C Programming

// C program to find quotient
// and remainder of two numbers
#include <stdio.h>

// Driver code
int main()
{
	int A, B, quotient = 0, remainder = 0;

	// Ask user to enter the two numbers
	printf("Enter two numbers A and B : \n");

	// Read two numbers from the user || A = 17, B = 5
	scanf("%d%d", &A, &B);

	// Calculate the quotient of A and B using '/' operator
	quotient = A / B;

	// Calculate the remainder of A and B using '%' operator
	remainder = A % B;

	// Print the result
	printf("Quotient when A/B is: %d\n", quotient);
	printf("Remainder when A/B is: %d", remainder);

	return 0;
}
Copy The Code & Try With Live Editor

Output

x
+
cmd
Enter two numbers A and B: Quotient when A / B is: 3
Remainder when A / B is: 2

#3 Example- Program to find Quotient and Remainder using function

Code - C Programming

#include <stdio.h>
// Function to computer quotient
int quotient(int a, int b){
   return a / b;
}

// Function to computer remainder
int remainder(int a, int b){
   return a % b;
}

int main(){
    int num1, num2, quot, rem;
    printf("Enter dividend: ");    
    scanf("%d", &num1);
    printf("Enter divisor: ");    
    scanf("%d", &num2);
    
    //Calling function quotient()    
    quot = quotient(num1, num2);

    //Calling function remainder()    
    rem = remainder(num1, num2);
    printf("Quotient is: %d\n", quot);    
    printf("Remainder is: %d", rem);
    return 0;
}
Copy The Code & Try With Live Editor

Output

x
+
cmd
Enter dividend: 15
Enter divisor: 2
Quotient is: 7
Remainder is: 1
Advertisements

Demonstration


C Programing to Compute Quotient and Remainder-DevsEnv

Next
Appending into a File in C Programming