Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.swift
- // Lab6.1
- //
- import Foundation
- var tab: [Double] = Array(repeating: 1.0, count: 12)
- for i in tab {
- print(i)
- }
- ////////////////////////////////////////////////////
- //
- // main.swift
- // Lab6.2
- //
- import Foundation
- //a
- var emptyArr: [Int] = []
- for _ in 1...10{
- let num = Int.random(in: 1..<101)
- emptyArr.append(num)
- }
- for i in emptyArr {
- print(i, terminator:" ")
- }
- print("\n")
- //b
- guard let wczyt = Int(readLine()!) else
- {
- fatalError("Zla liczba")
- }
- print("\n")
- emptyArr.insert(wczyt, at: 0)
- for i in emptyArr {
- print(i, terminator:" ")
- }
- //c, d
- print("\n")
- let x = Int.random(in: 1..<10)
- emptyArr.insert(wczyt, at: x)
- for i in emptyArr {
- print(i, terminator:" ")
- }
- print("\n")
- //////////////////////////////////////////////////
- //
- // main.swift
- // Lab6.3
- //
- import Foundation
- print("Podaj liczbe elementow")
- guard let liczba = Int(readLine()!) else
- {
- fatalError("Zla liczba")
- }
- if(liczba>0){
- var tab: [Int] = []
- for i in 0..<liczba {
- print("Podaj element nr \(i) :")
- guard let elem = Int(readLine()!) else
- {
- fatalError("Zla liczba")
- }
- tab.append(elem)
- }
- print("Podaj liczbe sprawdzenia")
- guard let l1 = Int(readLine()!) else
- {
- fatalError("Zla liczba")
- }
- if(tab[0]==l1)
- {
- print("Liczba \(l1) jest 1szym elem tab")
- }
- if(tab[liczba-1]==l1)
- {
- print("Liczba \(l1) jest ostat elem tab")
- }
- }
- else{
- fatalError("Zla liczba")
- }
- //////////////////////////////////////////////
- //
- // main.swift
- // Lab6.4
- //
- import Foundation
- print("Podaj liczbe elementow")
- guard let liczba = Int(readLine()!) else
- {
- fatalError("Zla liczba")
- }
- if(liczba>0){
- var tab1: [Int] = []
- var tab2: [Int] = []
- for _ in 0..<liczba {
- let elem = Int.random(in: 1...20)
- tab1.append(elem)
- }
- for _ in 0..<liczba {
- let elem = Int.random(in: 1...20)
- tab2.append(elem)
- }
- tab1.sort()
- tab2.sort()
- if(tab1==tab2)
- {
- print("Tablice maja jednakowe elementy ")
- }
- }
- else{
- fatalError("Zla liczba")
- }
- /////////////////////////////////////////////
- //
- // main.swift
- // Lab6.5
- //
- import Foundation
- let mac: [[Int]] = [[10, 20, 30], [40, 50, 60]]
- for i in 0 ..< mac.count {
- for j in 0 ..< mac[i].count{
- print("\(mac[i][j])", terminator:" ")
- }
- print()
- }
- ////////////////////////////////////////////////
- //
- // main.swift
- // Lab6.6
- //
- import Foundation
- print("Podaj liczbe wierszy")
- guard let w = Int(readLine()!) else
- {
- fatalError("Zla liczba")
- }
- print("Podaj liczbe kolumn")
- guard let k = Int(readLine()!) else
- {
- fatalError("Zla liczba")
- }
- if(w>0 && k>0){
- var tab: [[Double]] = [[]]
- for i in 0..<w {
- for _ in 0..<k {
- tab[i].append(Double.random(in: -100.0...100.0))
- }
- tab.append([])
- }
- for x in 0 ..< tab.count {
- for y in 0 ..< tab[x].count{
- print("\(tab[x][y])", terminator:" ")
- }
- print()
- }
- var maks: Double = -100.0
- var mini: Double = 100.0
- var ix1: Int = 0
- var iy1: Int = 0
- var ix2: Int = 0
- var iy2: Int = 0
- for x in 0 ..< tab.count {
- for y in 0 ..< tab[x].count{
- if(tab[x][y]<mini){
- mini=tab[x][y]
- ix1 = x
- iy1 = y
- }
- if(tab[x][y]>maks){
- maks=tab[x][y]
- ix2 = x
- iy2 = y
- }
- }
- }
- print("Min to: \(mini) a indeksy to: \(ix1), \(iy1)")
- print("Max to: \(maks) a indeksy to: \(ix2), \(iy2)")
- }
- else{
- fatalError("Zle liczby")
- }
- /////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement