+ 1

Pow (Swift)

var a = 2, b = 3 //(a+4b)(a–3b)+a^2 var res = (a + (4 * b)) * (a - (3 * b)) + pow(Double(a),2) print(res) //I do not know how to square, for some reason the answer is not displayed

23rd Apr 2021, 7:47 PM
Viktor Kizera
Viktor Kizera - avatar
9 Respuestas
+ 3
This one import Foundation var a = 2, b = 3 //(a+4b)(a–3b)+a^2 var res = (a + 4 * b) * (a - 3 * b) + Int(pow(Double(a),2)) print(res) Becomes - 94 Don't know if you need a Integer Result, or a Double Result
23rd Apr 2021, 9:14 PM
Coding Cat
Coding Cat - avatar
+ 1
Wow , thank you very much!!!!🎉
23rd Apr 2021, 9:16 PM
Viktor Kizera
Viktor Kizera - avatar
0
Try: import Foundation I've tested this, and it's running import Foundation var res = pow(5.0,2) print(res) https://stackoverflow.com/questions/24012511/mathematical-functions-in-swift
23rd Apr 2021, 8:23 PM
Coding Cat
Coding Cat - avatar
0
And why here 5.0?
23rd Apr 2021, 8:25 PM
Viktor Kizera
Viktor Kizera - avatar
0
Only for testing. I don't know anything about Swift
23rd Apr 2021, 8:26 PM
Coding Cat
Coding Cat - avatar
0
But this is also working: import Foundation var a = 5 var res = pow(Double(a), 2) print(res)
23rd Apr 2021, 8:34 PM
Coding Cat
Coding Cat - avatar
0
Yes it works, but for some reason it doesn't work for me in the equation (
23rd Apr 2021, 8:37 PM
Viktor Kizera
Viktor Kizera - avatar
0
Hmm, looks like another issue. 🤔
23rd Apr 2021, 8:41 PM
Coding Cat
Coding Cat - avatar
0
Viktor Kizera Your'e welcome.
23rd Apr 2021, 9:21 PM
Coding Cat
Coding Cat - avatar