Prime number or not program in swift programming language. This is the basic set of program in every programming language swift basics. To print the prime number or not in swift. There are two different set of loops were used to print the output. If else function prints the output only it satisfies the condition only.
var n = 10
var i = 2
for i in 2 ... n-1
value = 1;
print("\(n)" + " not prime")
print("\(n)" + " prime")
10 is not prime
What is prime number and how to calculate
A prime number is a number bigger than one that has only two factors: itself and one. A prime number cannot be divided by another prime number without a remainder. 13 is an example of a prime number, although 15 is not because it may be divided by 5, 3, and 1, as well as by itself and 1.
A prime number is a number higher than 1 that has exactly two elements, namely 1 and the number itself. In other words, a prime number is one that cannot be divided into equal groups. Only if a number can be factorised as a product of two numbers can it be divided into groups with equal numbers of items/elements.