66 999
Assignments Done
99,2%
Successfully Done
In November 2018

Answer to Question #26387 in C# for patrick

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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
26.03.13, 15:15

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

Ask Your question

Submit
Privacy policy Terms and Conditions