Multiply by itself


We are going to write an algorithm that will multiply by itself. For example, if we take 10 * 10, it will return 100. Let’s dive in.

func sum(number: Int) -> Int {
    var result = 0
    for i in 1...number {
        result += number
    return result

Now if we type in any number, it should multiply itself. In our case, 4 multiply 4 would be 16.

sum(number: 4)     //  16



  • Article By :
    Founder of DaddyCoding. Studied Computer Science, Information System and Information Technology at BYU-Hawaii. Currently spending most of my time researching and learning on helping to expose making iOS apps.

Random Posts

Leave a Reply

Your email address will not be published. Required fields are marked *