Pattern Programming using swift Programming language, Logical Programming ,Swift Learning, competitive programming.

pattern Programming, pattern programming using swift Programming language, logical Programming, swift learining, competitive programming, most frequently interview asked program, pattern asked in interview as fresher label

#Pattern Programming using Swift Programming language.

swift is new programming language come in market in 2014. it is developed by the developers of apple Inc before swift , iOS developer use objective c to develop the application , in 2014 apple came in marker with swift and start working with swift , as we see swift is new in market  and growing day by day now developer use swift frequently because swift provide many feature that is not present in objective c but that is not today topic .
Today topic is pattern programming , in interview for the fresher label company frequently asked to make a pattern and there is a company who came in campus for iOS developer position asked to make a pattern and you use swift as a language your impact is going good on the interviewer.
you can use any language logic will be same the only difference in the syntax. 
here are some basic pattern program and one program form the array . take a look and partice all the pattern these program are very easy. every cs student should know these program.
(1) func patternone(a: Int){
for i in 1...5{
    for j in 1...i{
        print("*", terminator:"")
    }
    print("\n")
  }
}
print(patternone(a: 5))
Output:- 
*

**

***

****

*****


(2)func patternTwo(lineYouWant: Int){
    for i in 1...lineYouWant{
       for j in 1...i{
          print(j, terminator:"")
        }
        print("\n")
    }
}
print(patternTwo(lineYouWant: 6))
Output:-
1

12

123

1234

12345

123456


(3)func patternThree(lineYouWant: Int){
    for i in 1...lineYouWant{
        for j in 1...i{
            print(i, terminator:"")
        }
        print("\n")
    }
}
print(patternThree(lineYouWant: 6))
Output:-
1

22

333

4444

55555

666666

(4)func patternFour(lineYouWant: Int){
    for i in 1...lineYouWant{
        for j in 1...i{
            print(i + j,terminator:"")
        }
        print("\n")
    }
}
print(patternFour(lineYouWant: 6))
Output:-
2

34

456

5678

678910

789101112

(5)func patternFive(linesYouWant: Int){
    for i in 1...linesYouWant{
        for j in 1...i {
            var m = i + j
            if(m % 2 == 0){
                print("1",terminator:"")
            }else{
                print("0",terminator:"")
            }
        }
        print("\n")
    }
}
print(patternFive(linesYouWant: 5))
Output:-
1

01

101

0101

10101

(6)func patternSix(linesYouWant: Int){
    var N = 1
    for i in 1...linesYouWant{
        for j in 1...i{
            print(N,terminator: "")
            N = N + 1
        }
        print("\n")
    }
}
nSix(linesYouWant: 5))
OUtput:-
1

23

456

78910

1112131415

(7)func patternSeven(linesYouWant: Int){
    for i in 1...linesYouWant{
        var n = 5
        for j in 1...i{
            print(n,terminator:"")
            n = n - 1
        }
        print("\n")
    }
}
print(patternSeven(linesYouWant: 5))
Output:-
5

54

543

5432

54321


(8)func patternEight(outerLine: Int){
var n = 5
        for i in 1...outerLine{
        for j in 1...i{
           print(n + 1 - i,terminator:"")
        }
            print("\n")
    }
}
print(patternEight(outerLine: 5))
Output:-
5

44

333

2222

11111


(9)func patternNine(outerLine: Int){
    //var n = 5
    for i in 1...outerLine{
        for j in 1...outerLine + 1 - i{
            print("*",terminator:"")
        }
        print("\n")
    }
}
print(patternNine(outerLine: 5))
OutPut:-
*****

****

***

**

*

(10) Swift program to print the sum of the array:-
func ElementInArray(input: [Int]){
    var array = input
    var sum = 0
    for i in array{
       sum = sum + i
    }
    print(sum)
}
print(ElementInArray(input: [1,2,3,4,5]))
Output:-
15

(11)func patternTen(outerLine: Int){
   for i in 1...outerLine{
        for j in 1...outerLine + 1 - i{
            print(i,terminator:"")
        }
        print("\n")
    }
}
print(patternTen(outerLine: 5))
Output:-
11111

2222

333

44

5

(12)func patternEleven(outerLine: Int){
    for i in 1...outerLine{
        for j in 1...outerLine + 1 - i{
            print(j,terminator:"")
        }
        print("\n")
    }
}
print(patternEleven(outerLine: 5))
Output:-
12345

1234

123

12

1

(13)func patternTwelve(outerLine: Int){
    for i in 1...outerLine{
        for j in 1...outerLine + 1 - i{
            print(outerLine + 1 - i,terminator:"")
        }
        print("\n")
    }
}
print(patternTwelve(outerLine: 5))
Output:-
55555

4444

333

22

1

(14)func patterThirteen(outerLine: Int){
    for i in 1...outerLine{
        for j in 1...outerLine + 1 - i{
            print(outerLine + 1 - j,terminator:"")
       }
        print("\n")
    }
}
print(patterThirteen(outerLine: 5))
Output:-
54321

5432

543

54

5
these are easy label swift pattern program , in my next post i an going to post average label pattern program.
you have problem to understand comment me ,for any enquiry comment me.
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