Exercises
Numbers
- input integers
xandyand print their sum, difference, product, quotient and remainder - input integers
xandyand print one of these 3:- they are equal
- x is bigger
- y is bigger
Strings
- write "Hello world!" to screen
- input
namefrom user and greet him, for example "Hello Bob!" - input
namefrom 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
nfrom user, and print "abc1", "abc2".. etc where numbers increase untiln - input integer
nfrom user, it must be an even and positive number - input integer
nand find factorial of that number - input integers
mandnand print all pairs "(0,0)", "(0,1)",.."(1,0)".. etc where first number goes0..mand second0..n - print Fibonacci numbers smaller than 50
- input 5 numbers and print the smallest
- input integer
nand print number of digits, e.g. 1111 -> 4 - input integer
nand 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 printsstextntimes - make a function
fact(n: Integer)that returns factorial ofn(and call it frommainto test it) - make a function
fib(n: Integer)that returns Fibonacci ofn