0

Hi, I want to create a function in CS that tests a number. If it is positive, the function calculate its square (x²)but if.....

.....it is negative, the function calculate its cubic (x³) and then I want to call up the function for the number 3. How can I do that?

22nd Dec 2020, 12:22 PM
Elia John
Elia John - avatar
5 ответов
+ 1
private double Func(double n) { return Math.Pow(n, n>=0?2:3); }
22nd Dec 2020, 6:46 PM
hossein B
hossein B - avatar
0
well. well. the obvious answer. did you tried attempting that before you could answer here? if i have to do it. I would first check the number using if statement.
22nd Dec 2020, 12:42 PM
Rellot's screwdriver
Rellot's screwdriver - avatar
0
Yes
22nd Dec 2020, 12:44 PM
Elia John
Elia John - avatar
0
did you get stuck somewhere while you were doing the assignment?
22nd Dec 2020, 12:45 PM
Rellot's screwdriver
Rellot's screwdriver - avatar
0
Thanks
23rd Dec 2020, 6:07 AM
Elia John
Elia John - avatar