Advertisement
QwertyAvatar

Swift 5

Nov 7th, 2022
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.07 KB | Software | 0 0
  1. //
  2. //  main.swift
  3. //  Zad 5.1
  4. //
  5.  
  6. import Foundation
  7.  
  8. print("Podaj maksymalna liczbe do sprawdzenia:")
  9. guard let licz = Int(readLine()!) else {
  10.         fatalError("Zla liczba")
  11. }
  12.  
  13. var x1: Int = 1
  14. var x2: Int = 1
  15. var x3: Int = 0
  16. var nr: Int = 3
  17.  
  18. if(x1<=licz)
  19. {
  20.     print("1 i 2 element ciagu to: \(x1) , \(x2)")
  21. }
  22. else {
  23.     print("Brak elementow ciagu mniejszych")
  24. }
  25.  
  26. while(x3 <= licz)
  27. {
  28.     x3 = x2 + x1
  29.     if(x3>licz)
  30.     {
  31.         print("Element wiekszy od licz! ")
  32.         break
  33.     }
  34.     else{
  35.         print("Element nr \(nr) to \(x3)")
  36.     }
  37.     x1 = x2
  38.     x2 = x3
  39.     nr+=1
  40. }
  41.  
  42. /////////////////////////////////////////////////////
  43.  
  44. //
  45. //  main.swift
  46. //  Zad 5.2
  47. //
  48.  
  49. import Foundation
  50.  
  51. print("Podaj maksymalna liczbe do sprawdzenia:")
  52. guard let licz = Int(readLine()!) else {
  53.         fatalError("Zla liczba")
  54. }
  55.  
  56. if(licz>2)
  57. {
  58.     let Poczatek: Int = 1
  59.     let Koniec: Int = Int(floor(sqrt(Double(licz))))
  60.     var IloscDzielnikow: Int = 0
  61.    
  62.     for i in stride(from: Poczatek, to: Koniec+1, by: 1){
  63.         if(licz%i==0){
  64.             IloscDzielnikow+=1
  65.         }
  66.     }
  67.     if(IloscDzielnikow == 1)
  68.     {
  69.         print("Liczba pierwsza")
  70.     }
  71.     else{
  72.         print ("Liczba nie jest pierwsza")
  73.     }
  74. }
  75. else if (licz == 2){
  76.     print("Liczba jest pierwsza")
  77. }
  78. else{
  79.     print("Podanej liczby nie mozna sprawdzic")
  80. }
  81.  
  82. //////////////////////////////////////////////////
  83.  
  84. //
  85. //  main.swift
  86. //  Zad 5.3
  87. //
  88.  
  89. import Foundation
  90.  
  91. print("Podaj liczbe do sredniej geom:")
  92. guard let licz = Int(readLine()!) else {
  93.         fatalError("Zla liczba")
  94. }
  95. if ((String(licz).count) >= 3)
  96. {
  97.     let slowo = String(licz)
  98.     var suma: Int = 0
  99.     for()
  100.     {
  101.        
  102.     }
  103.     var sl1: Int = Int(String(slowo[slowo.startIndex]))!
  104.     var sl2: Int = Int(String(slowo[slowo.index(slowo.startIndex, offsetBy: 1)]))!
  105.     var sl3: Int = Int(String(slowo[slowo.index(slowo.startIndex, offsetBy: 1)]))!
  106.    
  107.     let srgeo: Double = Double(pow(suma, 1/3))
  108.     print("\(srgeo)")
  109. }
  110. else{
  111.     print ("Liczba mniej niz trzycyfrowa")
  112. }
  113.  
Tags: swift
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement