+ 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?
5 Respuestas
+ 4
int pcode = 2440;
int pdigit = pcode/1000; //pdigit = 2
Then do whatever you want with pdigit.
+ 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
+ 1
@Ivan G,
that, your answer, is also the first algorithm that came into my mind after reading the problem 😂
+ 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.
0
allright, thanks for the answers