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();
}
Output

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 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2024 Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz