Odd or even program in a swift programming language

Odd or even program in a swift programming language. This program will help you to find the number is odd or even number in swift. To find the number is odd or even we must initialize the value before the condition like here we have initialized the value n=5, to check the number is odd or even in swift programming language

var n=5
    if(n % 2 == 0)

    {        print("\(n) is even")

    }

else    {

        print("\(n) is odd")

    }

 

Output:

5 is odd

Swift odd or even program explanation

Swift odd or even program for beginners, A number that can be divided into two equal classes is called an even number. A number that cannot be split into two equal classes is called an odd number. Using if else statement in this program it will execute the condition whether it is safisfied the condition to print the output.

What is odd and even number

Odd numbers are those that end in 1,3,5,7, or 9, whereas even numbers are those that end in 0,2,4,6, or 8. Numbers like 13, 25, 37, 49, and so on are odd numbers, while numbers like 22, 34, 70, 68, and so on are even numbers.