chess board grain number calculator

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 4 Exercise 8
Using std_lib_facilities.h by Bjarne Stroustrup.

//	Philipp Siedler
//	Bjarne Stroustrup's PP
//	Chapter 4 Exercise 8

#include "std_lib_facilities.h"

int main() {

	int squareNum = 1;
	int grainCount = 1;
	int sumGrainCount = 0;

	for (int i = 1; i < 65; i++) {
		squareNum = i;
		grainCount *= 2;
		sumGrainCount += grainCount;

		cout << "Square number: " << squareNum << " / Grain number on square: " << grainCount << " / Total grain number: " << sumGrainCount << '\n';
	}

	keep_window_open(".");
}
Output:
Square number: 1 / Grain number on square: 2 / Total grain number: 2
Square number: 2 / Grain number on square: 4 / Total grain number: 6
Square number: 3 / Grain number on square: 8 / Total grain number: 14
Square number: 4 / Grain number on square: 16 / Total grain number: 30
Square number: 5 / Grain number on square: 32 / Total grain number: 62
Square number: 6 / Grain number on square: 64 / Total grain number: 126
Square number: 7 / Grain number on square: 128 / Total grain number: 254
Square number: 8 / Grain number on square: 256 / Total grain number: 510
Square number: 9 / Grain number on square: 512 / Total grain number: 1022
Square number: 10 / Grain number on square: 1024 / Total grain number: 2046
Square number: 11 / Grain number on square: 2048 / Total grain number: 4094
Square number: 12 / Grain number on square: 4096 / Total grain number: 8190
Square number: 13 / Grain number on square: 8192 / Total grain number: 16382
Square number: 14 / Grain number on square: 16384 / Total grain number: 32766
Square number: 15 / Grain number on square: 32768 / Total grain number: 65534
Square number: 16 / Grain number on square: 65536 / Total grain number: 131070
Square number: 17 / Grain number on square: 131072 / Total grain number: 262142
Square number: 18 / Grain number on square: 262144 / Total grain number: 524286
Square number: 19 / Grain number on square: 524288 / Total grain number: 1048574
Square number: 20 / Grain number on square: 1048576 / Total grain number: 2097150
Square number: 21 / Grain number on square: 2097152 / Total grain number: 4194302
Square number: 22 / Grain number on square: 4194304 / Total grain number: 8388606
Square number: 23 / Grain number on square: 8388608 / Total grain number: 16777214
Square number: 24 / Grain number on square: 16777216 / Total grain number: 33554430
Square number: 25 / Grain number on square: 33554432 / Total grain number: 67108862
Square number: 26 / Grain number on square: 67108864 / Total grain number: 134217726
Square number: 27 / Grain number on square: 134217728 / Total grain number: 268435454
Square number: 28 / Grain number on square: 268435456 / Total grain number: 536870910
Square number: 29 / Grain number on square: 536870912 / Total grain number: 1073741822
Square number: 30 / Grain number on square: 1073741824 / Total grain number: 2147483646
Square number: 31 / Grain number on square: -2147483648 / Total grain number: -2
Square number: 32 / Grain number on square: 0 / Total grain number: -2
Square number: 33 / Grain number on square: 0 / Total grain number: -2
Square number: 34 / Grain number on square: 0 / Total grain number: -2
Square number: 35 / Grain number on square: 0 / Total grain number: -2
Square number: 36 / Grain number on square: 0 / Total grain number: -2
Square number: 37 / Grain number on square: 0 / Total grain number: -2
Square number: 38 / Grain number on square: 0 / Total grain number: -2
Square number: 39 / Grain number on square: 0 / Total grain number: -2
Square number: 40 / Grain number on square: 0 / Total grain number: -2
Square number: 41 / Grain number on square: 0 / Total grain number: -2
Square number: 42 / Grain number on square: 0 / Total grain number: -2
Square number: 43 / Grain number on square: 0 / Total grain number: -2
Square number: 44 / Grain number on square: 0 / Total grain number: -2
Square number: 45 / Grain number on square: 0 / Total grain number: -2
Square number: 46 / Grain number on square: 0 / Total grain number: -2
Square number: 47 / Grain number on square: 0 / Total grain number: -2
Square number: 48 / Grain number on square: 0 / Total grain number: -2
Square number: 49 / Grain number on square: 0 / Total grain number: -2
Square number: 50 / Grain number on square: 0 / Total grain number: -2
Square number: 51 / Grain number on square: 0 / Total grain number: -2
Square number: 52 / Grain number on square: 0 / Total grain number: -2
Square number: 53 / Grain number on square: 0 / Total grain number: -2
Square number: 54 / Grain number on square: 0 / Total grain number: -2
Square number: 55 / Grain number on square: 0 / Total grain number: -2
Square number: 56 / Grain number on square: 0 / Total grain number: -2
Square number: 57 / Grain number on square: 0 / Total grain number: -2
Square number: 58 / Grain number on square: 0 / Total grain number: -2
Square number: 59 / Grain number on square: 0 / Total grain number: -2
Square number: 60 / Grain number on square: 0 / Total grain number: -2
Square number: 61 / Grain number on square: 0 / Total grain number: -2
Square number: 62 / Grain number on square: 0 / Total grain number: -2
Square number: 63 / Grain number on square: 0 / Total grain number: -2
Square number: 64 / Grain number on square: 0 / Total grain number: -2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.