- 1

Not getting proper output

package main import "fmt" func scale(num int,factor *float32){ } func main() {     var num int      var factor float32     fmt.Scanln(&num)     fmt.Scanln(&factor)     scale(num, &factor)     fmt.Println(num) }

14th Jul 2021, 4:28 PM
Chinmay Anand
Chinmay Anand - avatar
8 ответов
+ 6
Looks like you wrote the code on another platform and paste it here. Try deleting it and rewrite on code playground
14th Jul 2021, 5:21 PM
Simba
Simba - avatar
+ 3
I just removed the invalid characters from your code. Can I see the task what you're trying to do? I mean copy the task and paste it here
17th Jul 2021, 7:36 AM
Simba
Simba - avatar
+ 1
Done Simba thanks buddy
17th Jul 2021, 8:17 AM
Chinmay Anand
Chinmay Anand - avatar
+ 1
package main import "fmt" func scale(num *float32, factor float32){ *num *= factor } func main() { var num float32 var factor float32 fmt.Scanln(&num) fmt.Scanln(&factor) scale(&num, factor) fmt.Println(num) }
18th Apr 2023, 3:41 PM
Esa Krissa
Esa Krissa - avatar
0
I didn't getSimba
15th Jul 2021, 3:40 AM
Chinmay Anand
Chinmay Anand - avatar
0
Simba not getting the actual output. Where I am wrong can u plz make me understand.
17th Jul 2021, 6:55 AM
Chinmay Anand
Chinmay Anand - avatar
0
The solution of Scale Factor Code Coach is package main import "fmt" func scale(x *float32, y *float32){ *x*=y } func main() { var num float32 var factor float32 fmt.Scanln(&num) fmt.Scanln(&factor) scale(&num, factor) fmt.Println(num) } Here, in the main() function, when the scale function is called with arguments, &num passes the memory address of the value, and factor is a direct value. Now, in function scale, the parameters are passed as x *float32 because it can retrieve the value from the memory address and put it into the calculation. Also, the actual arguments passed in the scale function are both float32.
14th Jan 2024, 5:55 AM
Abhishek Kumar
Abhishek Kumar - avatar