+ 1

math.pow

i have a postal code 2440 and i only want to use math.pow on the 2 is that possible? if so how?

17th Oct 2016, 8:48 PM
stef
5 Respuestas
+ 4
int pcode = 2440; int pdigit = pcode/1000; //pdigit = 2 Then do whatever you want with pdigit.
17th Oct 2016, 8:58 PM
Zen
Zen - avatar
+ 2
This realization is universal and less magical than Zen's one (will work when code lenght will change). var code = "2440"; // our postal code var first = code[0]; // first letter of code var firstInt = Convert.ToInt32(first); // first letter converted to int var result = Math.Pow(firstInt, 2); // result
17th Oct 2016, 8:55 PM
Ivan G
Ivan G - avatar
+ 1
@Ivan G, that, your answer, is also the first algorithm that came into my mind after reading the problem 😂
18th Oct 2016, 8:20 PM
Erwin Mesias
Erwin Mesias - avatar
+ 1
int pcode = 2440; double result = Math.Pow(double.Parse(""+(""+pcode)[0]), exponent); //that^ gets the first number and raises it to the value you placed to exponent variable. This is similar to what Ivan G has already posted, I just put them in a single line.
18th Oct 2016, 8:39 PM
Erwin Mesias
Erwin Mesias - avatar
0
allright, thanks for the answers
17th Oct 2016, 9:26 PM
stef