Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Introduction to Programming
- ## Part-Time Students – 2026
- ### Three-Day Practical Lab
- The exercises should be completed in order. Each exercise introduces one or two new programming concepts while reinforcing concepts from the previous exercises.
- ---
- # Day 1 – First Program, Variables, Operators, Input, and Conditions
- ### Task 1 – Hello, World!
- Start the computer and a suitable IDE.
- Create a new program that prints:
- "Hello, World!"
- to the console.
- **Concepts:** IDE, source code, compiling/running a program, console output.
- ---
- ### Task 2 – Variables and Number Systems
- Define a variable with a suitable type and name that stores the approximate distance from the Earth to the Moon in kilometres:
- 384400
- Print its value.
- Then change the integer literal so that the same value is written in hexadecimal notation.
- Run the program again and verify that the printed value is still the same.
- **Concepts:** variables, data types, integer literals, decimal and hexadecimal numeral systems.
- ---
- ### Task 3 – Arithmetic Operators
- Calculate and print the remainder of dividing 15 by 2.
- Try several other values.
- **Concepts:** arithmetic operators, integer division, remainder operator.
- ---
- ### Task 4 – Reading Input
- Ask the user to enter their age.
- Read the value from the console and print how old the user will be in 10 years.
- Example:
- Enter your age: 25
- In 10 years, you will be 35 years old.
- **Concepts:** console input, variables, conversion from text to integer, arithmetic expressions.
- ---
- ### Task 5 – Conditions
- Extend the program from Task 4.
- If the entered age is greater than 40, print:
- "You are old."
- Otherwise, print:
- "You are young."
- **Concepts:** Boolean expressions, comparison operators, `if`/`else`.
- ---
- # Day 2 – Loops and Arrays
- ### Task 6 – A Simple Loop
- Print all integer numbers from 0 to 100.
- Modify the program to print:
- * only the even numbers from 0 to 100;
- * the numbers from 100 down to 0.
- **Concepts:** loops, loop variables, conditions inside loops.
- ---
- ### Task 7 – Arrays
- Define an array containing 10 integer values.
- Print all elements of the array.
- Then multiply each element by 2 and print the resulting values.
- **Concepts:** arrays, indexing, array traversal, modifying array elements.
- ---
- ### Task 8 – Fibonacci Sequence
- Define a method named `Fibonacci` that accepts an integer `n` and returns the n-th element of the Fibonacci sequence.
- Use the method to print the first 40 elements of the Fibonacci sequence.
- **Concepts:** methods, parameters, return values, loops, reuse of code.
- ---
- ### Task 9 – Fibonacci Using Recursion
- Define another method named `FibonacciRecursion`.
- It should calculate the n-th Fibonacci number recursively.
- Use both methods to calculate several small Fibonacci numbers and verify that the results are the same.
- **Concepts:** recursion, base cases, recursive calls.
- **Note:** Do not use the recursive method to calculate large Fibonacci numbers.
- ---
- # Day 3 – Methods and Simple Array Algorithms
- ### Task 10 – Finding the Minimum
- Define a method that accepts an integer array and returns its smallest element.
- Create an array in the main program, call the method, and print the result.
- Example array:
- `{ 7, 2, 9, 4, 1, 8 }`
- Expected result:
- `Minimum: 1`
- **Concepts:** passing arrays to methods, traversal, keeping a current minimum.
- ---
- ### Task 11 – Finding the Maximum
- Define a method that accepts an integer array and returns its largest element.
- Test the method using the same array from Task 10.
- **Concepts:** algorithm reuse, traversal, keeping a current maximum.
- ---
- ### Task 12 – Selecting Odd Elements
- Define a method that accepts an integer array and returns only its odd elements.
- Print the returned elements.
- For example:
- Input:
- `{ 7, 2, 9, 4, 1, 8 }`
- Result:
- `{ 7, 9, 1 }`
- **Concepts:** filtering data, conditions, constructing a result.
- ---
- ### Task 13 – Bubble Sort
- Define a method that sorts an integer array in ascending order using the bubble sort algorithm.
- Do not use a built-in sorting method.
- Print the array before sorting and after sorting.
- Example:
- Before:
- `7 2 9 4 1 8`
- After:
- `1 2 4 7 8 9`
- **Concepts:** nested loops, comparing adjacent elements, swapping values, simple sorting algorithms.
- ---
- # Final Challenge
- Create one integer array and use the methods from Tasks 10–13 to:
- 1. print the original array;
- 2. find and print its minimum element;
- 3. find and print its maximum element;
- 4. print only its odd elements;
- 5. sort the array;
- 6. print the sorted array.
- The purpose of this final task is to combine several small methods into one complete program.
Advertisement
Add Comment
Please, Sign In to add comment