Online C++ Compiler

#include <bits/stdc++.h> using namespace std; #define row 3 #define col 3 bool check_square(long double num) { long double val = sqrt(num); return ((val - floor(val)) == 0); } bool check_fibonacci(int num) { return check_square(5 * num * num + 4) || check_square(5 * num * num - 4); } int Fibonacci_cells(int matrix[row][col]) { int count = 0; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { int total = matrix[i][j]; if ((i == 0 && j == 0) || (i == row - 1 && j == 0) || (i == 0 && j == col - 1) || (i == row - 1 && j == col - 1)) { total = total + 2; } else if (i == 0 || j == 0 || i == row - 1 || j == col - 1) { total = total + 3; } else { total = total + 4; } if (check_fibonacci(total)) { count++; } } } return count; } int main() { int matrix[row][col] = { { 1, 4, 1 }, { 2, 0, 1 }, { 5, 1, 1 } }; cout << "Count of cells in a matrix which give a Fibonacci number when the count of adjacent cells is added are: " << Fibonacci_cells(matrix); return 0; }