Dividing integer variables, Finding Quotients and Remainders - C++ Operator

C++ examples for Operator:Arithmetic Operator

Introduction

To find the remainder, use the percent sign (%).

This is often called the modulus operator.

Demo Code

#include <iostream>

using namespace std;

int main()/*from   w  w  w  .  j av a2s  . c om*/
{
  int first, second;

  cout << "Dividing 28 by 14." << endl;

  first = 28;
  second = 14;

  cout << "Quotient  " << first / second << endl;
  cout << "Remainder " << first % second << endl;
  cout << "Dividing 32 by 6." << endl;

  first = 32;
  second = 6;

  cout << "Quotient  " << first / second << endl;
  cout << "Remainder " << first % second << endl;
  return 0;
}

Result


Related Tutorials