DulcetAirman icon

sum range

DulcetAirman | PRO | 06/13/18 02:28:00 PM UTC | 0 ⭐ | 11649 👁️ | Never ⏰ | []
Kotlin |

260 B

|

None

|

0 👍

/

0 👎

fun main(args: Array<String>) {
    println(sum(100,1000))
}
 
fun sum(begin:Int, end:Int):Int {
    if(begin > end) throw IllegalArgumentException("'begin' must not be greater than 'end'")
    if(begin == end) return end
    return begin + sum(begin+1, end)
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎