#include #include long int numOfRookConfig(int n); int main() { int n = 8; printf("Number of Configuration = %d \n", numOfRookConfig(n)); return 0; } long int numOfRookConfig(int n) { /* Placing a Rook at any position blocks one row and one column. * So, only one rook can be placed in each row or column. * Say, a rook is placed at position 3,4 , then no other rook can be placed in both row 3 and row 4.This can be considered as decreasing the matrix by size 1. * If we start by placing a rook in first column of matrix there are n ways to do that. * It turns out to be factorial. */ if(n==1) return 1; return n * numOfRookConfig(n-1); }