- Related Questions & Answers
- Maximum number that can be display on Seven Segment Display using N segments in C++
- Maximum litres of water that can be bought with N Rupees in C++
- Maximum Number of Events That Can Be Attended in C++
- Maximum number of candies that can be bought in C
- Maximum circular subarray sum in C++\n
- Maximum money that can be withdrawn in two steps in C
- Find smallest number n such that n XOR n+1 equals to given k in C++
- Find maximum value of x such that n! % (k^x) = 0 in C++
- Find a positive number M such that gcd(N^M,N&M) is maximum in Python
- Maximum points of intersection n circles in C++
- Maximum points of intersection n lines in C++
- Divisors of n-square that are not divisors of n in C++ Program
- Maximum number of ones in a N*N matrix with given constraints in C++
- Maximum elements that can be made equal with k updates in C++
- Maximum possible time that can be formed from four digits in C++

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

We are given an input N which denotes the size of the chessboard. The task here is to find for any value of N, how many bishops can be placed on the NXN chessboard such that no two bishops can attack each other. Let’s understand with examples.

**Input** − N=2

**Output**− Maximum bishops that can be placed on N*N chessboard − 2 ( as shown above )

**Explanation** − As depicted above the only non-contradictory positions are where the bishops are placed. Bishops at-most for 2X2 chessboard.

**Input** − N=5

**Output**− Maximum bishops that can be placed on N*N chessboard: 8 ( as shown above )

We take an integer value N as input for chessboard dimensions.

Pass this N as argument to totalBishops(int n).

For N<1 invalid input, bishops count=0.

For N=1, only 1 position, bishop count=1.

Else bishops will be 2*(N-1)

Store this result in variable bishops.

Return the result.

#include <iostream> //to return maximum bishops possible int totalBishops(int n){ int bishops=0; if (n < 1) bishops= 0; else if (n == 1) bishops= 1; else bishops= 2 * (n - 1); return bishops; } int main(){ int N = 15; //for chessboard dimensions N*N printf("%d" ,totalBishops(N)); return 0; }

If we run the above code it will generate the following output −

28

Advertisements