https://rentry.org/PPP2_p67

// Code derived from Stroustrup's PPP2 book
// § 3.4 Operations and operators
// -beginning on p 67

#include <cmath>
#include <iostream>

using std::cin;
using std::cout;
using std::sqrt;

// simple program to exercise operators
int main()
{
  cout << "Please enter a floating-point value: ";
  double 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)  //
       << '\n';  // another name for newline (“end of line”) in output
}

build & run:

g++ -std=c++20 -O2 -Wall -pedantic ./ch_03/main_p67.cpp && ./a.out

PrevUpNext

Edit
Pub: 17 Jan 2023 06:26 UTC
Edit: 29 Apr 2023 06:12 UTC
Views: 675