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.

#include<stdio.h>
#include<math.h>

int main() {

  int n, i, root;

  printf("Enter a 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 a number:50                                                                                                                      
                                                                                                                                       
i = 1                                                                                                                                  
i = 4                                                                                                                                  
i = 9                                                                                                                                  
i = 16                                                                                                                                 
i = 25                                                                                                                                 
i = 36                                                                                                                                 
i = 49