Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
if(sqrt(size_of_array)*sqrt(size_of_array) == size_of_array)
{
// got a square
int rows = sqrt(size_of_array);
for(int i = 0;rows;i++)
{
for(int j = 0;j<rows;j++)
{
cout<<*(array+i*rows+j)<<"\t";
}
cout<<"\n";
}
}
another way for doing this would be:
#include <stdio.h>
#include <math.h>
void main()
{
const int size = 9;
int array[size] = {2,56,-87,37,65,226,17,398,14};/* an example */
bool issqr = false;
int z = 1;
while( z <= size && !issqr )
{
if( size == 1 )
{
issqr = true;
}
else if(( size/ z) == z && !( size % z ) && z != 1 )
{
issqr = true;
}
z++;
}
if( issqr )
{
/* got a square */
int row = z - 1;
for(int i = 0; i < size; i++ )
{
if( !(i%row) && i != 0 )
printf("\n");
printf("%d\t",array[i]);
}
}
}