Check the given number is perfect number or not in swift 3.0

Code: import UIKit var n = 28 var temp = n var sum = 0 for i in 1 ... n-1 {     if(n%i==0)     {         sum = sum + i     } } if(sum == temp) {     print("\(temp) is perfect number.") } else {      print("\(temp) is not perfect number.") } Result: ...

Find Factors of given number in swift 3.0

Code: import UIKit var n = 12 print("Factors of \(n) are:\n") for i in 1 ... n {     if(n%i==0)     {         print("\(i) " )     } } Result: ...

Sample demo application with text Field, button and label in swift 3.0

Here we are going to create simple iPhone app in iPhone with the help of  text Field, button and label. We have to make a simple app in which we have to show the content of textfield (entered by user into uitextfield) into label when user taps on button. First open your Xcode (i am using Xcode 8.1 here). When you open your Xcode it will ask to create new project or open a created project. choose your option. I am choosing to create...

Check the number is prime or not in swift 3.0

//code import UIKit var flag=0 var n = 13 var i = 2 for i in 2 ... n-1 {     if(n%i==0)     {         flag = 1;         break;     } } if(flag==1) {     print("\(n)" + " is not prime") } else {     print("\(n)" + " is  prime") } Result: ...