05 CSharp Advanced Functional Programming Exercises
05 CSharp Advanced Functional Programming Exercises
1. Action Point
Create a program that reads a collection of strings from the console and then prints them onto the console. Each
name should be printed on a new line. Use Action<T>.
Examples
Input Output
2. Knights of Honor
Create a program that reads a collection of names as strings from the console, appends "Sir" in front of every
name and prints it back in the console. Use Action<T>.
Examples
Input Output
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Examples
Input Output
1 4 3 2 1 7 13 1
4 5 -2 3 -5 8 -5
Examples
Input Output
1 10 1 3 5 7 9
odd
20 30 20 22 24 26 28 30
even
5. Applied Arithmetics
Create a program that executes some mathematical operations on a given collection. On the first line, you are given
a list of numbers. On the next lines, you are passed different commands that you need to apply to all the numbers
in the list:
"add" -> add 1 to each number
"multiply" -> multiply each number by 2
"subtract" -> subtract 1 from each number
"print" -> print the collection
"end" -> ends the input
Examples
Input Output
1 2 3 4 5 3 4 5 6 7
add
add
print
end
5 10 9 19
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Examples
Input Output
1 2 3 4 5 6 5 3 1
2
20 10 40 30 60 50 50 40 10 20
3
Examples
Input Output
4 Karl
Karl Anna Kris Yahto
Anna
Kris
4 Karl
Karl James George Robert Patricia
8. List of Predicates
Find all numbers in the range 1…N that are divisible by the numbers of a given sequence. On the first line, you will be
given an integer N – which is the end of the range. On the second line, you will be given a sequence of integers
which are the dividers. Use predicates/functions.
Examples
Input Output
10 2 4 6 8 10
1 1 1 2
100 20 40 60 80 100
2 5 10 20
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Finally, print all the guests who are going to the party separated by ", " and then add the ending "are going to
the party!". If no guests are going to the party print "Nobody is going to the party!". See the examples
below:
Examples
Input Output
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
All PRFM filter parameters will be a string (or an integer only for the "Length" filter). Each command will be valid
e.g. you won't be asked to remove a non-existent filter. The input will end with a "Print" command, after which
you should print all the party-goers that are left after the filtration. See the examples below:
Examples
Input Output
11. TriFunction
Create a program that traverses a collection of names and returns the first name, whose sum of characters is equal
to or larger than a given number N, which will be given on the first line. Use a function that accepts another
function as one of its parameters. Start by building a regular function to hold the basic logic of the program.
Something along the lines of Func<string, int, bool>. Afterward, create your main function which should
accept the first function as one of its parameters.
Examples
Input Output
350 Mary
Rob Mary Paisley Spencer
666 William
Paul Thomas William
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.