Teaching / Mobile Programming 1

HTML Assignments

Web version of the laboratory assignments. The left menu selects an assignment and the right panel shows the English assignment content.

HTML Assignments

L01 - Assignment 1

Assignment 1

Deadline:

12.03.2025

Task 1 - 1 pt

Implement a function that accepts one Int argument and prints all numbers from 1 to the given value.

If a number is divisible by:

  • 3 - the function prints "three"
  • 5 - the function prints "five"
  • 3 and 5 - the function prints "threefive"
  • in every other case, the function prints the numeric value
val num: Int = 15
println(foo(num))
>>  1
>>  2
>>  three
>>  4
>> five
>> three
>> 7
>> 8
>> three
>> five
>> 11
>> three
>> 13
>> 14
>> threefive

Task 2 - 1 pt

Create a program that checks whether a word provided by the user is a palindrome, meaning it reads the same from left to right and from right to left.

val word = "abba"
println(isPalindrome(word))
>>  true

Task 3 - 1 pt

Write a program that generates Pascal's triangle of a given height. Pascal's triangle is a numeric structure where each number is the sum of the two numbers directly above it in the previous row.

val height: Int = 4
println(printPascal(height))
>>       1
>>      1 1
>>     1 2 1
>>    1 3 3 1

Task 4 - 2 pts

Write a program that checks whether a given number is perfect, abundant, or deficient based on its aliquot sum.

val number: Int = 28
println(isPerfect(number))
>>       perfect
val number: Int = 12
println(isPerfect(number))
>>       abundant
val number: Int = 8
println(isPerfect(number))
>>       deficient

Examples:

  • 28: $1 + 2 + 4 + 7 + 14 = 28$ - perfect
  • 12: $1 + 2 + 3 + 4 + 6 = 16$ - abundant
  • 8: $1 + 2 + 4 = 7$ - deficient

Task 5 - 2 pts

Write a program that checks whether a given number is an Armstrong number.

val number: Int = 153
println(checkArmstrong(number))
>>       true

Examples: $$153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27$$ $$9 = 9^1$$ $$154 \neq 1^3 + 5^3 + 4^3 = 1 + 125 + 64$$

Task 6 - 1 pt

Write a function that checks whether a given number is prime.

val number: Int = 17
println(isPrime(number))
>> true

Task 7 - 1 pt

Implement a function that calculates the sum of all even numbers from 1 to the given value, inclusive.

val n: Int = 10
println(sumEven(n))
>> 30

Task 8 - 1 pt

Write a function that counts the number of vowels in a given word, ignoring letter case.

Assume the vowels are: a, e, i, o, u, y.

val word = "Programowanie"
println(countVowels(word))
>> 6

Grades

gradepoints
3.06 pts
3.57 pts
4.08 pts
4.59 pts
5.010 pts