I have written this code for C to print prime numbers from 1-300
GNU GCC Compiler shows the following error:
error: invalid operands to binary % (have ‘double’ and ‘int’)
if (sqrt(num) == 0 || sqrt(num) % 2 != 0)
My code is this:
#include <stdio.h>
#include <math.h>
int main() {
/*Created by Suvid Singhal Date:- January 2, 2017*/
int num;
printf("Welcome to 1-300 prime numbers C Program!!!");
for (num = 0; num <= 300; num++) {
if (sqrt(num) == 0 || sqrt(num) % 2 != 0) {
printf("%d\n", num);
} else {
continue;
}
}
return 0;
}