Advertisement
QwertyAvatar

Swift 2

Oct 10th, 2022 (edited)
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.50 KB | Software | 0 0
  1. //
  2. //  File.swift
  3. //  Zad2.1
  4. //
  5.  
  6. import Foundation
  7.  
  8. let rokAktualny = 2022
  9. var rok: String
  10. var rokW: Int = 0
  11. var lata: Int
  12.  
  13. print("Podaj rok urodzenia:")
  14. rok=readLine()!
  15. //rokW = Int(readLine()!)!
  16.  
  17. if let rU = Int(rok){
  18.     rokW = rU
  19. }
  20.  
  21. lata = rokAktualny - rokW //Int(rok)!
  22. print("Masz \(lata) lat")
  23.  
  24. /////////////////////////////////////////////////////////////////
  25.  
  26. //
  27. //  File.swift
  28. //  Zad2.2
  29. //
  30.  
  31. import Foundation
  32.  
  33. let pi: Double = 3.14
  34. var r: Double
  35. var Obw: Double = 0
  36. var P: Double = 0
  37.  
  38. print("Podaj promien:")
  39. r = Double(readLine()!)!
  40.  
  41. P = pi * pow(r, 2)
  42. Obw = 2 * pi * r
  43.  
  44. let P2 = String(format: "%.2f", P)
  45. let Obw2 = String(format: "%.2f", Obw)
  46.  
  47. print("Kolo o promieniu \(r) ma pole \(P2) i obwod \(Obw2) .")
  48.  
  49. ///////////////////////////////////////////////////////////////////
  50.  
  51. //
  52. //  File.swift
  53. //  Zad2.3
  54. //
  55.  
  56. import Foundation
  57.  
  58. var a: Double
  59. var V: Double = 0
  60. var Pc: Double = 0
  61.  
  62. print("Podaj bok:")
  63. a = Double(readLine()!)!
  64.  
  65. Pc = 6 * pow(a, 2)
  66. V = pow(a, 3)
  67.  
  68. let Pc2 = String(format: "%.2f", Pc)
  69. let V2 = String(format: "%.2f", V)
  70.  
  71. print("Szescian o boku \(a) ma pole \(Pc2) i objetosc \(V2) .")
  72.  
  73. ///////////////////////////////////////////////////////////////////////
  74.  
  75. //
  76. //  File.swift
  77. //  Zad2.4
  78. //
  79.  
  80. import Foundation
  81.  
  82. var a: Double = 0
  83. var b: Double = 0
  84. var s: Double = 0
  85. var z: Double = 0
  86. var cenaM: Double = 0
  87. var x: Double = 0
  88. var cenaC: Double = 0
  89.  
  90. print("Podaj a:")
  91. a = Double(readLine()!)!
  92. print("Podaj b:")
  93. b = Double(readLine()!)!
  94. print("Podaj z:")
  95. z = Double(readLine()!)!
  96. print("Podaj s:")
  97. s = Double(readLine()!)!
  98. print("Podaj cene za metr:")
  99. cenaM = Double(readLine()!)!
  100.  
  101. x = 2 * (a+b) + 2 * (z + b) - 3 * s
  102. cenaC = cenaM * x
  103.  
  104. let cenaC2 = String(format: "%.2f", cenaC)
  105. let x2 = String(format: "%.2f", x)
  106.  
  107. print("Dlugosc listwy z tych wymiarow to: \(x) a jej cena calkowita to \(cenaC) .")
  108.  
  109. ///////////////////////////////////////////////////////////
  110.  
  111. //
  112. //  File.swift
  113. //  Zad2.5, 2.6
  114. //
  115.  
  116. import Foundation
  117.  
  118. var a: Int = 0
  119. var b: Int = 0
  120. var c: Int = 0
  121. var wag1: Int = 1
  122. var wag2: Int = 2
  123. var wag3: Int = 3
  124. var sredA: Double = 0
  125. var sredB: Double = 0
  126.  
  127. a = Int.random(in:1..<10)
  128. b = Int.random(in:1..<10)
  129. c = Int.random(in:1..<10)
  130.  
  131. sredA = (Double(a+b+c) / 3)
  132. sredB = (Double)(a*wag1 + b*wag2 + c*wag3) / (Double)(wag1 + wag2 + wag3)
  133.  
  134. let sredA1 = String(format: "%.2f", sredA)
  135. let sredB1 = String(format: "%.2f", sredB)
  136.  
  137. print("Srednia 1 to \(sredA1) a srednia 2 to \(sredB1) .")
  138.  
  139.  
  140.  
Tags: swift
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement