Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // File.swift
- // Zad2.1
- //
- import Foundation
- let rokAktualny = 2022
- var rok: String
- var rokW: Int = 0
- var lata: Int
- print("Podaj rok urodzenia:")
- rok=readLine()!
- //rokW = Int(readLine()!)!
- if let rU = Int(rok){
- rokW = rU
- }
- lata = rokAktualny - rokW //Int(rok)!
- print("Masz \(lata) lat")
- /////////////////////////////////////////////////////////////////
- //
- // File.swift
- // Zad2.2
- //
- import Foundation
- let pi: Double = 3.14
- var r: Double
- var Obw: Double = 0
- var P: Double = 0
- print("Podaj promien:")
- r = Double(readLine()!)!
- P = pi * pow(r, 2)
- Obw = 2 * pi * r
- let P2 = String(format: "%.2f", P)
- let Obw2 = String(format: "%.2f", Obw)
- print("Kolo o promieniu \(r) ma pole \(P2) i obwod \(Obw2) .")
- ///////////////////////////////////////////////////////////////////
- //
- // File.swift
- // Zad2.3
- //
- import Foundation
- var a: Double
- var V: Double = 0
- var Pc: Double = 0
- print("Podaj bok:")
- a = Double(readLine()!)!
- Pc = 6 * pow(a, 2)
- V = pow(a, 3)
- let Pc2 = String(format: "%.2f", Pc)
- let V2 = String(format: "%.2f", V)
- print("Szescian o boku \(a) ma pole \(Pc2) i objetosc \(V2) .")
- ///////////////////////////////////////////////////////////////////////
- //
- // File.swift
- // Zad2.4
- //
- import Foundation
- var a: Double = 0
- var b: Double = 0
- var s: Double = 0
- var z: Double = 0
- var cenaM: Double = 0
- var x: Double = 0
- var cenaC: Double = 0
- print("Podaj a:")
- a = Double(readLine()!)!
- print("Podaj b:")
- b = Double(readLine()!)!
- print("Podaj z:")
- z = Double(readLine()!)!
- print("Podaj s:")
- s = Double(readLine()!)!
- print("Podaj cene za metr:")
- cenaM = Double(readLine()!)!
- x = 2 * (a+b) + 2 * (z + b) - 3 * s
- cenaC = cenaM * x
- let cenaC2 = String(format: "%.2f", cenaC)
- let x2 = String(format: "%.2f", x)
- print("Dlugosc listwy z tych wymiarow to: \(x) a jej cena calkowita to \(cenaC) .")
- ///////////////////////////////////////////////////////////
- //
- // File.swift
- // Zad2.5, 2.6
- //
- import Foundation
- var a: Int = 0
- var b: Int = 0
- var c: Int = 0
- var wag1: Int = 1
- var wag2: Int = 2
- var wag3: Int = 3
- var sredA: Double = 0
- var sredB: Double = 0
- a = Int.random(in:1..<10)
- b = Int.random(in:1..<10)
- c = Int.random(in:1..<10)
- sredA = (Double(a+b+c) / 3)
- sredB = (Double)(a*wag1 + b*wag2 + c*wag3) / (Double)(wag1 + wag2 + wag3)
- let sredA1 = String(format: "%.2f", sredA)
- let sredB1 = String(format: "%.2f", sredB)
- print("Srednia 1 to \(sredA1) a srednia 2 to \(sredB1) .")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement