Only outputting whole numbers

So i need to generate a 4 digit number that is a perfect square number and also divisible by 63.

Im getting confused as to where I work out the square root and only show whole numbers.
Do I create a new if statement, include it in my original if statement or put in in the same line as my divisible by 63 code?


#include <iostream>
#include <math.h>

int main() {
for(int n = 0001; n<9999; n++)
{
if
(n%63 == 0) //check if divisible by 63
{
std::cout << n << "\t" <<sqrt(n) << std::endl; //numbers and their square root numbers
}
}
return 0;
}
For numbers in the range 1000 - 9999, the whole numbers squared that produce a number in that range are 32 - 99.

So you need a loop that loops from 32 to 99 where that number squared is also exactly divisible by 63 (use the mod operator %).
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
   // 63 = 7*3*3 so any SQUARE will have to be of the form (square)*7*7*3*3 or square*441
   int i1 = sqrt( 999.9 / 441 ) + 1, i2 = sqrt( 9999.9 / 441 );
   for ( int i = i1; i <= i2; i++ ) cout << i * i * 441 << ' ';
}


1764 3969 7056 
Topic archived. No new replies allowed.