Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
C++ Program to Compute Quotient and Remainder

Program to Compute Quotient and Remainder in C

Posted on September 12, 2020May 24, 2021

Table of Contents

  • Program to Compute Quotient and Remainder in C
    • Compute Quotient and Remainder
      • Compute Quotient and Remainder in C – standard method
      • Compute Quotient and Remainder in C – Using user input
      • Compute Quotient and Remainder in C – Using function

Program to Compute Quotient and Remainder in C

In this tutorial, we will discuss the Program to Compute Quotient and Remainder in C

In this post, we are going to learn how to find quotient and remainder using two numbers via different 3 ways in C.

Compute Quotient and Remainder

Compute Quotient and Remainder in C – standard method

Program 1

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

int main()
{
    int dividend=200,divisor=12;
    int quotient,remainder;
    quotient=dividend/divisor;  // / operator use to compute quotient
    remainder=dividend%divisor;  // % operator use to compute remainder
    printf("Quotient = %d\n",quotient);
    printf("Remainder = %d\n",remainder);
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Quotient = 16
Remainder = 8

 

In this program,

  • integer variables dividend,divisor are declared and initialized
  • integer variables quotient,remainder are declared.
  • The dividend and divisor both are used to calculate quotient and remainder
  • Then,the program is displayed the output of using printf() function

 

Compute Quotient and Remainder in C – Using user input

Program 2

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

int main()
{
    int dividend,divisor;
    int quotient,remainder;
    printf("Enter dividend: " );
    scanf("%d",&dividend);
    printf("Enter divisor: " );
    scanf("%d",&divisor);
    quotient=dividend/divisor; // / operator use to compute quotient
    remainder=dividend%divisor; // % operator use to compute remainder
    printf("Quotient = %d\n",quotient);
    printf("Remainder = %d\n",remainder);
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Enter dividend: 200
Enter divisor: 15
Quotient = 13
Remainder = 5

 

  • Integer variables dividend,divisor are declared.
  • Integer variables quotient,remainder are declared.
  • The program asks input from the user
  • Then the user enters the input values for dividend and divisor.
  • The program will read the input using scanf() function and store the variables dividend and divisor respectively
  • The dividend and divisor both are used to calculate quotient and remainder.
  • Then,the program is displayed the output of using printf() function

 

Compute Quotient and Remainder in C – Using function

Program 3

#include <stdio.h>
#include <stdlib.h>
 int findQuitient(int a, int b){
   return a/b;
    }
    int findRemainder(int a, int b){
   return a%b;
    }
int main()
{
    int dividend,divisor;
    printf("Enter dividend: " );
    scanf("%d",&dividend);
    printf("Enter divisor: " );
    scanf("%d",&divisor);

    printf("Quotient = %d\n",findQuitient(dividend,divisor));
    printf("Remainder = %d\n",findRemainder(dividend,divisor));
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Enter dividend: 230
Enter divisor: 15
Quotient = 15
Remainder = 5

 

Approach

  • Declare dividend and divisor.
  • The program takes input from the user
  • Then the user enters the input value for  dividend and divisor.
  • the program will read the input using scanf() function and store the variables in dividend and divisor respectively
  • define the function findQuotient() and findRemainder() to find quotient and remainder
  • Call the function with argument to produce output
  • finally, the program displays the output using printf() function

 

Program 4

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

//user define function for find quotient
  void findQuotient(int a, int b){
   int Quotient= a/b;
   printf("Quotient = %d",Quotient);
    }
    //user define function for find remainder
    void findRemainder(int a, int b){
   int Remainder =a%b;
     printf("\nRemainder %d",Remainder);
    }
int main()
{
    int dividend,divisor;
    //integer variable declaration
    printf("Enter dividend: ") ;
    //Ask input from the user for dividend
    scanf("%d",&dividend);
    //Reading the input
    printf("Enter divisor: ") ;
    //Ask input from the user for divisor
     scanf("%d",&divisor);
    //Reading the input

    findQuotient(dividend,divisor);
    //Call the function for display quotient
    findRemainder(dividend,divisor);
    //Call the function for display remainder
    getch();
    return 0;
}


 

When the above code is executed, it produces the following result

Enter dividend: 54
Enter divisor: 6
Quotient = 9
Remainder = 0

 

Program 5

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

//user define function for find quotient
 void findQuotient(int a, int b){
   int Quotient= a/b;
   printf("Quotient = %d",Quotient);
    }
    //user define function for find remainder
    void findRemainder(int a, int b){
   int Remainder =a%b;
     printf("\nRemainder %d",Remainder);
    }
int main()
{
    int dividend=190,divisor=7;
    //integer variable declaration

    findQuotient(dividend,divisor);
    //Call the function for display quotient
    findRemainder(dividend,divisor);
    //Call the function for display remainder
    getch();
    return 0;
}



When the above code is executed, it produces the following result

Quotient = 24
Remainder = 2

 

Suggested for you

Data type in C language

Variable in C language

Operator in C anguage

While loop in C language

 

Similar post

Python Program to Compute Quotient and Remainder

Java Program to Compute Quotient and Remainder

C++ Program to Compute Quotient and Remainder

 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes