0
How to print out perfact squares in given range in C++?
m
11 Antworten
+ 1
A normal square is just something squared - any number, including decimals. The perfect squares are whole integers.
Also, I would just do this:
for (int i = 1; i <= end; ++i) cout << i * i << endl;
It's one line
+ 4
@Zeke yes but if begin <= i <= end, then
begin <= i*i </= end
+ 2
//range from begin to end
int i = 0;
while(i * i < begin)
++i;
for(;i * i <= end; ++i)
cout << i*i << endl;
+ 1
I thought it was the definition of a normal square
+ 1
👍.this code will help me
+ 1
void main ( )
{
int begin=1;
int end;
cin >> end;
cout << "perfact squares = \n";
for (;begin*begin<=end;begin++)
{
cout << begin*begin << " ";
}
system ("pause");
}
is this code right?
+ 1
thanks for help you gyz .this program ran and i got perfact squres in user specified range.bcs i have used your ideas
0
What is a "perfact square" ? :/ I might be able to help you but I need an explanation on this term for that
0
A perfect square is a number that can be expressed as the product of two equal integers. E.g. 4, 9, 16, 25, 36, 49, 64, etc...
So use a for loop starting at 2: for (int i = 2; ...
And then output i * i
0
what would be the syntax for finding perfact squares in given range
0
yes.thanks