The king and the Chees board. A king is so impressed by one of his courtiers thet he offers to give him whatever he desires. The wily courtier replies that all he wants are some grains, as many as could be placed on each square of a chess board. Specially, grains are to be placed on each square of a chess board, as follows. One grain is to be placed in the first square,two in the second square , four in the third square and so on. (We'll assume the squares are big enough to accommodate the increasing numbers of grains they're each expected to hold). Assuming anNxN chess board, WAP that displays the exacy number of grains required to cover an NxN board. Input: integer N , Output:integer P (number of grains)
The king and the Chees board. A king is so impressed by one of his courtiers thet he offers to give him whatever he desires. The wily courtier replies that all he wants are some grains, as many as could be placed on each square of a chess board. Specially, grains are to be placed on each square of a chess board, as follows. One grain is to be placed in the first square,two in the second square , four in the third square and so on. (We'll assume the squares are big enough to accommodate the increasing numbers of grains they're each expected to hold). Assuming anNxN chess board, WAP that displays the exacy number of grains required to cover an NxN board. Input: integer N , Output:integer P (number of grains)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images