C++ int type Divide integer variables, Find Quotients and Remainders

Introduction

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

This is often called the modulus operator.


#include <iostream>

using namespace std;

int main()/*  w  ww .  ja  va2s. c o m*/
{
  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;
}



PreviousNext

Related