Exercises
Numbers
- input integers
x
andy
and print their sum, difference, product, quotient and remainder - input integers
x
andy
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 untiln
- 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
andn
and print all pairs "(0,0)", "(0,1)",.."(1,0)".. etc where first number goes0..m
and second0..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 ofn
- 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 - make a function
printMultiple(n: Integer, s: String)
that printss
textn
times - make a function
fact(n: Integer)
that returns factorial ofn
(and call it frommain
to test it) - make a function
fib(n: Integer)
that returns Fibonacci ofn