https://rentry.org/PPP2_p113a

// Code derived from Stroustrup's PPP2 book
// § 4.4.2.3 for-statements
//  -and beginning on p 113

#include <iostream>

using std::cout;

// return the square of x
int square(int x) { return x * x; }

// calculate and print a table of squares of even numbers in the [0:100) range
int main()
{
  for (int i = 0; i < 100; i += 2)
    cout << i << '\t' << square(i) << '\n';
}

build & run:

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

PrevUpNext

Edit
Pub: 01 Feb 2023 14:12 UTC
Edit: 29 Apr 2023 08:25 UTC
Views: 399