-->

program to print/display all perfect square numbers lying between 1 and 'n'.

//program to print/display all perfect square numbers lying between 1 and 'n'.
#include<stdio.h>
#include<conio.h>
#include<math.h>void main()
{
   int factors,i,n;
   printf("enter  positive number for 'n'\n");
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    {
      if(sqrt(i)==int(sqrt(i))
        {                
          printf("the perfect squares are=%d ",i);
        }
  }
getch();
}
--------------------------------------------------------------------------------------------------------------------------------------
logics in mind:
->enter a number for range to get perfect square
->we have to go for repetitive process from number 1 to entered number 'n'.
->we get square root of number and then its integer value . This we can apply using loop as shown above.
->If we get same value then then we display that.
     for this, we have used 
                if(sqrt(i)==int(sqrt(i))
              it checks square root and its integer value

No comments:

Post a Comment