- 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) }
8 ответов
+ 6
Looks like you wrote the code on another platform and paste it here.
Try deleting it and rewrite on code playground
+ 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
+ 1
Done Simba thanks buddy
+ 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)
}
0
I didn't getSimba
0
Simba not getting the actual output. Where I am wrong can u plz make me understand.
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.