# Simple Program of Swift Asked In InterView.

Here i am going to introduce you all with the simple programs thats frequently asked in the interview if you going to interview for the developer . and i choose the swift programming language that is very easy programming language and if you want to became iOS Developer swift is very useful .
all program are here very simple and it is for the fresher , college student.
if you want to learn swift programming you can start with these programs these programs make you understand the swift programming and give the basic knowledge of programming language.
and if you are not interested in the swift take the question and write in the language you prefer like c , c++ and java or any other language .
these programs are for the basic understanding and interview asked these questions

(1) program to get reminder after divide by 3 in any number

func check(num: Int)-> Int{
    var n = num
    var result = n % 3
    return result
}
print(check(num: 1234))

OUTPUT:-
1

(2)smallest and largest if - else

func checknum(a: Int, b: Int)-> Int{
    if (a > b ){
        return a - b
    }
    else{
        return a + b
        }
}
print(checknum(a: 30, b: 40))
print(checknum(a: 50, b: 10))

OUTPUT:-

70
40

(3) ternary operator

func ternariy(a: Int,b: Int)-> Int{
    let result = a > b ? a - b : a + b
    return result
}
print(ternariy(a: 30, b: 40))
print(ternariy(a: 50, b: 10))

OUTPUT:-

70
40

(4)Program to print the percentage of the number

func percentage(Hindi: Double,English: Double, SS: Double,S: Double,Sanskrit: Double)-> Double{
    var per = (Hindi + English + SS + S + Sanskrit) / 5
    return per
}
print(percentage(Hindi: 23, English: 17, SS: 87, S: 23, Sanskrit: 43))

OUTPUT:-

38.6

(5) print count 1 to 10

var a = 1
while (a <= 10){
    print(a)
    a = a + 1
}

OUTPUT
1
2
3
4
5
6
7
8
9
10

(6) print count in the reverse order with the margin of 2

var b = 20
while(b >= 2){
    print(b)
    b = b - 2
}
OUTPUT
20
18
16
14
12
10
8
6
4
2
(7) Program print the sum of the number

func sumOfNumber(num: Int)->Int{
   var number = num
   var result = 0
    while(number > 0){
        var r = number % 10
         result = r + result
        number = number / 10
    }
    return result
}
print(sumOfNumber(num: 11111))
OUTPUT-
5

(8) program to print the product of any number

func productOfNumber(num: Int)-> Int{
    var  numbr = num
    var result = 1
    while(numbr > 0){
       var reminder = numbr % 10
       result = reminder * result
       numbr = numbr / 10
    }
    return result
}
print(productOfNumber(num: 43259))
OUTPUT:-

1080

(9) Program to find the factorial Number

func factorial(num: Int)->Int{
    var n = num
    var fact = 1
    if (n < 0){
        print("factorial is not possible")
    }else{
        while(n > 1)
        {
             fact = fact * n
            n = n - 1
        }
    }
    return fact
}
print(factorial(num: 5))

OUTPUT:-

120

//10 program to convert binary into decimal

func decimal(num: Int)-> Int{
    var n = num
    var j = 1
    var dec = 0
    while(n > 0){
        var rem = n % 10
        var d = rem * j
         dec = dec + d
        j = j * 2
        n = n / 10
    }
  return dec
}
print(decimal(num: 1111))

OUTPUT:-
15

After doing all these 10 programs i am sure you get a little idea of the programming and start taking interest in the programming 

Thank you

Comments

Popular posts from this blog

Simple function to Encryption on Mobile No,email id or any user information in react-native

Counter function for adding item in cart and select the item in the list