+ 5
Challenge
Raise a number to the square using only: - While or for - Operators + - (NOT MULTIPLICATION *) Terms * Do not use modules or libraries that give the value squared * You can use the language you want ;)
14 Answers
+ 11
https://code.sololearn.com/c522HM1YsqQC/?ref=app
+ 6
Nice challenge
+ 6
Not working with decimal numbers yet, but with integers is ok.
https://code.sololearn.com/cz16O6j32Oho/?ref=app
+ 4
https://code.sololearn.com/cuP03Nb6newm/?ref=app
+ 2
Updated
a^n power function for any(1<=n) degrees of integers (negative int.s too)
https://code.sololearn.com/cIl5A4JQFLTa/?ref=app
+ 2
Hi. Here is my code in python. It work for negative numbers too.
https://code.sololearn.com/cpX0YpB7nJnc/?ref=app
+ 1
@HeisAbdulaziz your code doesn't work with negative numbers if you want to raise them to even power. in example (-3)^2
+ 1
as i've tagged )))
// a^n=1*a*a*a*a...*a
// input: a n (a>0,n>0 a,n=int)
// output: a^n
but it isn't pow i have some bugs
+ 1
oh sorry, I'm probably just blind haha
+ 1
Using sum of first n odd integers to give the square of n:
https://code.sololearn.com/cUKbPSDr4iTi/?ref=app
+ 1
'''
Challenge
Raise a number to the square using only:
- While or for
- Operators + - (NOT MULTIPLICATION *)
Terms
* Do not use modules or libraries that give the value squared
* You can use the language you want ;
'''
number=int(input());result=0
for i in range (number):
result+=number
print('The square of',number,'is',result)
0
It does not look like it been solved for decimals yet.
You could make a larger challenge if complex numbers were included!