0

How to print out perfact squares in given range in C++?

m

4th Nov 2017, 4:07 PM
Maria Waheed
Maria Waheed - avatar
11 Answers
+ 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
4th Nov 2017, 7:18 PM
Zeke Williams
Zeke Williams - avatar
+ 4
@Zeke yes but if begin <= i <= end, then begin <= i*i </= end
4th Nov 2017, 8:05 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 2
//range from begin to end int i = 0; while(i * i < begin) ++i; for(;i * i <= end; ++i) cout << i*i << endl;
4th Nov 2017, 6:32 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 1
I thought it was the definition of a normal square
4th Nov 2017, 6:30 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 1
šŸ‘.this code will help me
4th Nov 2017, 6:34 PM
Maria Waheed
Maria Waheed - avatar
+ 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?
5th Nov 2017, 1:36 AM
Maria Waheed
Maria Waheed - avatar
+ 1
thanks for help you gyz .this program ran and i got perfact squres in user specified range.bcs i have used your ideas
5th Nov 2017, 1:43 AM
Maria Waheed
Maria Waheed - avatar
0
What is a "perfact square" ? :/ I might be able to help you but I need an explanation on this term for that
4th Nov 2017, 5:10 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
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
4th Nov 2017, 5:49 PM
Zeke Williams
Zeke Williams - avatar
0
what would be the syntax for finding perfact squares in given range
4th Nov 2017, 6:30 PM
Maria Waheed
Maria Waheed - avatar
0
yes.thanks
4th Nov 2017, 6:31 PM
Maria Waheed
Maria Waheed - avatar