Question #26387

write a program that prints all perfect squares found in each row of a matrice.

Expert's answer

#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;

}

#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

Assignment Expert26.03.13, 15:15You'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