C program to compute Quotient and Remainder
How to write a C program to compute Quotient and Remainder?
In this we will learn to write a C program to compute Quotient and remainder of two given numbers when they are divided. In other words, two number num1 and num2 are given and we need to find the Quotient and Remainder when num1 is divided by num2.
Syntax:
quotient = dividend / divisor; remainder = dividend % divisor;
Example:
Input: num1 = 2, num2 = 6 Output: Quotient = 0, Remainder = 2 Input: num1 = 17, num2 = 5 Output: Quotient = 3, Remainder = 2
Steps to compute Quotient and Remainder:
- Step 1: Start
- Step 2: Declare the variable num1=2, num2=4, Quotient and Remainder.
- Step 3: Read input num1 and num2 from the user or predefine it according to the need.
- Step 4: 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 5: Display the Quotient and Remainder in the stdout console.
- Step 6: Program end.
Working:
Example 1 :
A simple program where we will compute the Quotient and Remainder of two variables that are predefined.
#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; }
Output:
Quotient = 9 Remainder = 3
Example 2 :
Program where we will compute the Quotient and Remainder of 2 numbers given by the users.
#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; }
Input:
Enter dividend: 42 Enter divisor: 8
Output:
Quotient = 5 Remainder = 2
Example 3 :
Program where we will compute the Quotient and Remainder of two number in C using functions.
#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; }
Input:
Enter dividend: 456 Enter divisor: 3
Output:
Quotient = 152 Remainder = 0
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment