Program to check perfect squares between 1 to 100
#include<iostream>
#include<conio.h>
using namespace std;
int perfect_square(int
number);
int main()
{
int number = 0, perfect_sq = 0;
cout
<< "\n\n\t\t __ Program to print Perfect
Square betwenen 1 to 100 __";
cout
<< "\n\n\n Perfect Squares -
";
for(number = 1; ; number++)
{
perfect_sq
= perfect_square(number);
if (perfect_sq <= 100)
{
cout
<< perfect_sq << " , ";
}
else
{
break;
}
}
cout
<< "\b\b
";
getch();
return 0;
}
int perfect_square(int
number)
{
return number * number;
}
A
number is said to be a perfect square is it is the square of any other number.
For Example – 0, 1, 4, 9, 16, 25 etc. or in other words it can be said that if
the square of a number is a whole number then it’s a perfect square.
No comments:
Post a Comment