Course of Raku / Essentials
/ The MAIN
function / Exercises / Print the
sum
Solution: Print the sum
This program consists of a single MAIN function that
takes two typed arguments, both of which are built from the arguments
from the command line.
Code
Here is the solution:
sub MAIN(Int $a, Int $b) {
say $a + $b;
}
🦋 Find the program in the file print-the-sum.raku.
Output
Try different input numbers:
$ raku exercises/the-main-function/print-the-sum.raku 500 700
1200You can also try running the program without the arguments or with the arguments of different types and see what happens. We’ll talk about handling those cases in the second part of the course.
Course navigation
← Print the sum | Perimeter of a rectangle →
Translations of this page: English • Deutsch • Español • Italiano • Latviešu • Nederlands • Български • Русский • Українська