[Solved] I want to check if sq. root of a number is int


Do something like below :

double a = 5, b = 25;
short count = 0;
for (double i = a; i <= b; i++) {
    double sqrut=sqrt(i); 
    if ((int)(sqrut) == sqrut) {
        printf("Perfect square %.0f found\n", i);
        count++;
    }
}
printf("Total number of perfect squares is %d\n", count);

or like below :

double a = 5, b = 25;
short count = 0;
for (double i = a; i <= b; i++) {
    int sqrut = sqrt(i); // An implicit casting happens here.
    if ((sqrut * sqrut) == i) {
        printf("Perfect square %.0f found\n", i);
        count++;
    }
}
printf("Total number of perfect squares is %d\n", count);

4

solved I want to check if sq. root of a number is int