operator exercise

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 3 Try This Page 68
Using std_lib_facilities.h by Bjarne Stroustrup.

[code language=”cpp”]
// Philipp Siedler
// Bjarne Stroustrup’s PP
// Chapter 3 Try This Page 68

#include "std_lib_facilities.h"
#define Res 10

int main()
{
cout << "Please enter a integer value\n";
int n;

cin >> n;
cout << "n ==" << n
<< "\nn + 1 ==" << n + 1
<< "\nthree times n ==" << 3 * n
<< "\ntwice n ==" << n + n
<< "\nn squared ==" << n*n
<< "\nhalf of n ==" << n / 2
<< "\nsquare root of n ==" << sqrt(n)
<< "\nremainder of n " << n % 2
<< "\nmodulor of n and 2 ==" << n % 2
<< "\nmodulor of n and 3 ==" << n % 3
<< ‘\n’;
keep_window_open();
}
[/code]

Output:
Please enter a integer value
5
n ==5
n + 1 ==6
three times n ==15
twice n ==10
n squared ==25
half of n ==2
square root of n ==2.23607
remainder of n 1
modulor of n and 2 ==1
modulor of n and 3 ==2
Please enter a character to exit

Newsletter Updates

Enter your email address below to subscribe to our newsletter

Leave a Reply

Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124