wingman007

ExcercisesIntroduction2ProgrammingPart-Time

Sep 14th, 2026 (edited)
31,210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.79 KB | Software | 0 0
  1. # Introduction to Programming
  2.  
  3. ## Part-Time Students – 2026
  4.  
  5. ### Three-Day Practical Lab
  6.  
  7. The exercises should be completed in order. Each exercise introduces one or two new programming concepts while reinforcing concepts from the previous exercises.
  8.  
  9. ---
  10.  
  11. # Day 1 – First Program, Variables, Operators, Input, and Conditions
  12.  
  13. ### Task 1 – Hello, World!
  14.  
  15. Start the computer and a suitable IDE.
  16.  
  17. Create a new program that prints:
  18.  
  19. "Hello, World!"
  20.  
  21. to the console.
  22.  
  23. **Concepts:** IDE, source code, compiling/running a program, console output.
  24.  
  25. ---
  26.  
  27. ### Task 2 – Variables and Number Systems
  28.  
  29. Define a variable with a suitable type and name that stores the approximate distance from the Earth to the Moon in kilometres:
  30.  
  31. 384400
  32.  
  33. Print its value.
  34.  
  35. Then change the integer literal so that the same value is written in hexadecimal notation.
  36.  
  37. Run the program again and verify that the printed value is still the same.
  38.  
  39. **Concepts:** variables, data types, integer literals, decimal and hexadecimal numeral systems.
  40.  
  41. ---
  42.  
  43. ### Task 3 – Arithmetic Operators
  44.  
  45. Calculate and print the remainder of dividing 15 by 2.
  46.  
  47. Try several other values.
  48.  
  49. **Concepts:** arithmetic operators, integer division, remainder operator.
  50.  
  51. ---
  52.  
  53. ### Task 4 – Reading Input
  54.  
  55. Ask the user to enter their age.
  56.  
  57. Read the value from the console and print how old the user will be in 10 years.
  58.  
  59. Example:
  60.  
  61. Enter your age: 25
  62. In 10 years, you will be 35 years old.
  63.  
  64. **Concepts:** console input, variables, conversion from text to integer, arithmetic expressions.
  65.  
  66. ---
  67.  
  68. ### Task 5 – Conditions
  69.  
  70. Extend the program from Task 4.
  71.  
  72. If the entered age is greater than 40, print:
  73.  
  74. "You are old."
  75.  
  76. Otherwise, print:
  77.  
  78. "You are young."
  79.  
  80. **Concepts:** Boolean expressions, comparison operators, `if`/`else`.
  81.  
  82. ---
  83.  
  84. # Day 2 – Loops and Arrays
  85.  
  86. ### Task 6 – A Simple Loop
  87.  
  88. Print all integer numbers from 0 to 100.
  89.  
  90. Modify the program to print:
  91.  
  92. * only the even numbers from 0 to 100;
  93. * the numbers from 100 down to 0.
  94.  
  95. **Concepts:** loops, loop variables, conditions inside loops.
  96.  
  97. ---
  98.  
  99. ### Task 7 – Arrays
  100.  
  101. Define an array containing 10 integer values.
  102.  
  103. Print all elements of the array.
  104.  
  105. Then multiply each element by 2 and print the resulting values.
  106.  
  107. **Concepts:** arrays, indexing, array traversal, modifying array elements.
  108.  
  109. ---
  110.  
  111. ### Task 8 – Fibonacci Sequence
  112.  
  113. Define a method named `Fibonacci` that accepts an integer `n` and returns the n-th element of the Fibonacci sequence.
  114.  
  115. Use the method to print the first 40 elements of the Fibonacci sequence.
  116.  
  117. **Concepts:** methods, parameters, return values, loops, reuse of code.
  118.  
  119. ---
  120.  
  121. ### Task 9 – Fibonacci Using Recursion
  122.  
  123. Define another method named `FibonacciRecursion`.
  124.  
  125. It should calculate the n-th Fibonacci number recursively.
  126.  
  127. Use both methods to calculate several small Fibonacci numbers and verify that the results are the same.
  128.  
  129. **Concepts:** recursion, base cases, recursive calls.
  130.  
  131. **Note:** Do not use the recursive method to calculate large Fibonacci numbers.
  132.  
  133. ---
  134.  
  135. # Day 3 – Methods and Simple Array Algorithms
  136.  
  137. ### Task 10 – Finding the Minimum
  138.  
  139. Define a method that accepts an integer array and returns its smallest element.
  140.  
  141. Create an array in the main program, call the method, and print the result.
  142.  
  143. Example array:
  144.  
  145. `{ 7, 2, 9, 4, 1, 8 }`
  146.  
  147. Expected result:
  148.  
  149. `Minimum: 1`
  150.  
  151. **Concepts:** passing arrays to methods, traversal, keeping a current minimum.
  152.  
  153. ---
  154.  
  155. ### Task 11 – Finding the Maximum
  156.  
  157. Define a method that accepts an integer array and returns its largest element.
  158.  
  159. Test the method using the same array from Task 10.
  160.  
  161. **Concepts:** algorithm reuse, traversal, keeping a current maximum.
  162.  
  163. ---
  164.  
  165. ### Task 12 – Selecting Odd Elements
  166.  
  167. Define a method that accepts an integer array and returns only its odd elements.
  168.  
  169. Print the returned elements.
  170.  
  171. For example:
  172.  
  173. Input:
  174.  
  175. `{ 7, 2, 9, 4, 1, 8 }`
  176.  
  177. Result:
  178.  
  179. `{ 7, 9, 1 }`
  180.  
  181. **Concepts:** filtering data, conditions, constructing a result.
  182.  
  183. ---
  184.  
  185. ### Task 13 – Bubble Sort
  186.  
  187. Define a method that sorts an integer array in ascending order using the bubble sort algorithm.
  188.  
  189. Do not use a built-in sorting method.
  190.  
  191. Print the array before sorting and after sorting.
  192.  
  193. Example:
  194.  
  195. Before:
  196.  
  197. `7 2 9 4 1 8`
  198.  
  199. After:
  200.  
  201. `1 2 4 7 8 9`
  202.  
  203. **Concepts:** nested loops, comparing adjacent elements, swapping values, simple sorting algorithms.
  204.  
  205. ---
  206.  
  207. # Final Challenge
  208.  
  209. Create one integer array and use the methods from Tasks 10–13 to:
  210.  
  211. 1. print the original array;
  212. 2. find and print its minimum element;
  213. 3. find and print its maximum element;
  214. 4. print only its odd elements;
  215. 5. sort the array;
  216. 6. print the sorted array.
  217.  
  218. The purpose of this final task is to combine several small methods into one complete program.
  219.  
Advertisement
Add Comment
Please, Sign In to add comment