SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
C++ Basics
Exercise:
Self-test Exercises
Question:18 | ISBN:9780321531346 | Edition: 7

Question

Write a complete C++ program that reads two whole numbers into two variables of type int, and then outputs both the whole number part and the remainder when the first number is divided by the second. This can be done using the operators / and %.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Program Code:

#include <iostream>
using namespace std;

int main ()
{
    //Reads two whole numbers into two variables 
    //of data type int
    int firstNumber, secondNumber;
    cout << "Enter two interger numbers: ";
    cin >>firstNumber >> secondNumber;
    
    //Display outputs both the whole number part and the 
    //remainder when the first number is divided by the second. 
    cout << firstNumber << " is divided by " << secondNumber
        << " are equals to  " << (firstNumber/secondNumber) 
        << " and a remainder is " << (firstNumber%secondNumber)
        << endl;
    return 0;
}

Output of the program code:

Enter two interger numbers: 100 9                                                                                                    
100 is divided by 9 are equals to  11 and a remainder is 1 

 

0 0

Discussions

Post the discussion to improve the above solution.