Algorithm


  • Step 1: Declare the variable num1=2, num2=4, Quotient and Remainder.
  • Step 2: Read input num1 and num2 from the user or predefine it according to the need.
  • Step 3: Use the syntax provided to find the Quotient and remainder while using num1 and num2 and store the value in variables assigned to them.
  • Step 4: Display the Quotient and Remainder in the stdout console

 

Code Examples

#1 Example-program compute the Quotient and Remainder of two variables that are predefined.

Code - C Programming

#include<stdio.h>
int main()
{
    int num1, num2, quotient, remainder;
    num1=156;
    num2=17;
    // Computes quotient
    quotient = num1 / num2;
    // Computes remainder
    remainder = num1 % num2;
    printf("Quotient = %d\n", quotient);
    printf("Remainder = %d", remainder);
    return 0;
}
Copy The Code & Try With Live Editor

Output

x
+
cmd
Quotient = 9
Remainder = 3

#2 Example-Program Quotient and Remainder of 2 numbers given by the users

Code - C Programming

#include<stdio.h>
int main()
{
    int num1, num2, quotient, remainder;
    printf("Enter dividend: ");
    scanf("%d", &num1);
    printf("Enter divisor: ");
    scanf("%d", &num2);
    // Computes quotient
    quotient = num1 / num2;
    // Computes remainder
    remainder = num1 % num2;
    printf("Quotient = %d\n", quotient);
    printf("Remainder = %d", remainder);
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
Enter dividend: 42
Enter divisor: 8

Output

x
+
cmd
Quotient = 5
Remainder = 2

#3 Example-Program Quotient and Remainder of two number in C using functions.

Code - C Programming

#include<stdio.h>
int main()
{
    int num1, num2, quotient, remainder;
    printf("Enter dividend: ");
    scanf("%d", &num1);
    printf("Enter divisor: ");
    scanf("%d", &num2);
    // Computes quotient
    quotient = quo(num1,num2);
    // Computes remainder
    remainder = rem(num1 , num2);
    printf("Quotient = %d\n", quotient);
    printf("Remainder = %d", remainder);
    return 0;
}
int quo(int a, int b)
{
    return a/b;
}
int rem(int n, int m)
{
    return n%m;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
Enter dividend: 456
Enter divisor: 3

Output

x
+
cmd
Quotient = 152
Remainder = 0
Advertisements

Demonstration


C Programing Example to Compute Quotient and Remainder-DevsEnv

Next
Appending into a File in C Programming