#include <iostream>
#include <cmath>
using namespace std;
const int n = 3;
typedef int Matrix[n][n];
/* Returns true if the given number is a perfect square */
bool check_number(int number)
{
double sqrt = sqrt(number);
return (sqrt * sqrt == number);
}
/* Finds and prints all matrix elements
& * which are perfect squares */
void find_numbers(Matrix& matrix)
{
for (int x = 0; x < n; x++)
for (int y = 0; y < n; y++)
if (check_number(matrix[x][y]))
cout << matrix[x][y] << endl;
}
int main()
{
Matrix matrix = { { 4, -7,& 16},
{22,& 8,& 0 },
& {64, 17, -23} };
find_numbers(matrix);
return 0;
}
Comments
You're welcome. We are glad to be helpful. If you really liked our service please press like-button beside answer field. Thank you!
Leave a comment