C++ Program to Compute Quotient and Remainder

Find quotient and remainder

C++ program to compute quotient and remainder has been shown here. Find here the algorithm, pseudocode and time complexity of the program. The flowchart of the problem can be found here.






1. C++ Program & output to Compute Quotient and Remainder

Code has been copied
/********************************************
           alphabetacoder.com
C++ program to compute quotient and remainder
*********************************************/
#include <iostream>

using namespace std;

int main() {
    //initialize two variables
    int a = 17, b = 5;
    int q, r;

    //find the quotient
    q = a / b;
    //find the remainder
    r = a % b;
    // display result
    cout << "When " << a << " is divided by " << b << ", quotient is " << q << " and remainder is " << r << ".";
    
    return 0;
}

Output


When 17 is divided by 5, quotient is 3 and remainder is 2.