#include <stdio.h>
#include <cs50.h>
#include <unistd.h>
#include <math.h>
void rationalSquareRoots(void);
int main(void) {
rationalSquareRoots();
}
void rationalSquareRoots(void) {
for(float i = 0; ; i++) {
if(sqrt(i) % 1 == 0) {
printf("%f\n", i);
}
sleep(1);
}
}
I've encountered the following problem while attempting to make a program which prints out all numbers with rational square roots (well, all numbers up to the point of overflowing, I guess).
14:19: error: invalid operands to binary expression ('double' and 'int')
while(sqrt(i) % 1 == 0) {
The problem seems to be in the % operator? Is it not supported in if
statements? What's the solution?