Exercises
Numbers
- input integers
x
and y
and print their sum, difference, product, quotient and remainder
- input integers
x
and y
and print one of these 3:
- they are equal
- x is bigger
- y is bigger
Strings
- write "Hello world!" to screen
- input
name
from user and greet him, for example "Hello Bob!"
- input
name
from user and greet him only if his name is "Bob"
Loops
- print all positive even integers less than 10
- print sum of first 10 positive integers
- input integer
n
from user, and print "abc1", "abc2".. etc where numbers increase until n
- input integer
n
from user, it must be an even and positive number
- input integer
n
and find factorial of that number
- input integers
m
and n
and print all pairs "(0,0)", "(0,1)",.."(1,0)".. etc where first number goes 0..m
and second 0..n
- print Fibonacci numbers smaller than 50
- input 5 numbers and print the smallest
- input integer
n
and print number of digits, e.g. 1111 -> 4
- input integer
n
and print number with reverse digits, e.g. 123 -> 321 (hint: use mod operator %)
Functions
- make a function
square(n: Integer)
that returns square of n
- make a function
rectArea(w: Integer, h: Integer)
that returns area of a rectangle
- make a function
bmi(weight: Real, height: Real)
that returns BMI of a person
following the formula from here.
- make a function
printMultiple(n: Integer, s: String)
that prints s
text n
times
- make a function
fact(n: Integer)
that returns factorial of n
(and call it from main
to test it)
- make a function
fib(n: Integer)
that returns Fibonacci of n