1 – topshiriq
package ScalaOneHomeWork
import scala.io.StdIn.readLine
object ScalaOneHomeWork extends App {
print("a:")
var a = readLine().trim.toDouble
print("b:")
var b = readLine().trim.toDouble
print("c:")
var c = readLine().trim.toDouble
var U: Double = 0
if (a > b*b)
{
U = (a*a+4*a*b*c+c*c)/(a-b*b)
}
println(U)}
2-Topshiriq
No’l bilan tugaydigan, no’ldan farqli butun sonlar ketma-ketligida ishora o‘zgarishlar soni aniqlansin. (Masalan, 1 ,-34, 8 ,4,-5,0 ketma-ketlikda ishora 3 marta o‘zgaradi)
import scala.io.StdIn.readInt
object Scala13 extends App {
var n = readInt()
var f = false
if(n>0)
f = true
var cnt = 0
n = readInt()
while (n!=0) {
if(n>0 && !f){
cnt=cnt+1
f = true
} else {
if(n<0 && f){
cnt=cnt+1
f = false
}
}
n = readInt()
}
println(cnt)
}0>
Do'stlaringiz bilan baham: |