C Program to find perfect square numbers between 1 to n


In this program, You will learn how to find perfect square numbers between 1 to n in C.


Some list of perfect square numbers is: 1 4 9 16 25 36 49 64


Example: How to find perfect square numbers between 1 to n in C

Run it Now
#include<stdio.h>
#include<math.h>

int main() {

   int n, i, root;

   printf("Enter the Number :");
   scanf("%d", &n);

   for (i = 1; i <= n; i++) {

       root = sqrt(i);
       root = root*root;

       if (i == root) {
           printf("\ni = %d", i);
       }
   }

   return 0;
}

Output:

Enter the Number :50
i = 1
i = 4
i = 9
i = 16
i = 25
i = 36
i = 49