Programming Examples

Write a program to find the perfect squares from 1 to 500.


Write a program to find the perfect squares from 1 to 500.?

Solution

# include <stdio.h>
#include <math.h>
void main()
{
int i,count,x;
float c;
clrscr();
printf(“\n\n”);
printf(“ Perfect squares from 1 to 500\n”);
count=0;
for(i=1;i<=500;i++)
{
 c=sqrt(i);
 x=floor(c); /* For rounding up floor() is used. */
 if(c==x)
 {
 printf(“\t%5d”,i);
 count++;
 }
}
printf(“\n\n Total Perfect Squares =%d\n”,count);
getch();
}
▶ RUN

Output/ Explanation:

OUTPUT:

Perfect squares from 1 to 500

1 4 9 16 25 36 49 64 81 121 144

169 196 225 256 289 324 361 400 441 484

Total Perfect Squares = 22

Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad