// Exercises
// 2026 part-time students – 3 days
// 1. Start a computer and a suitable IDE, and create a program that prints "Hello, World!" to the console.
// 2. Define a variable with a suitable type and name that can hold the distance to the Moon. First, specify the value using the decimal numeral system, and then change the literal to represent the same value in hexadecimal.
// 3. Print to the console the remainder of dividing 15 by 2.
// 4. Ask the user to enter their age and tell them how old they will be in 10 years.
// 5. If the age from the previous task is greater than 40, print "You are old"; otherwise, print "You are young."
// 6. Print the numbers from 0 to 100 to the console.
// 7. Define an array of 10 integer values. Multiply each element by 2 and print the results.
// 8. Define a method named Fibonacci that returns the n-th element of the Fibonacci sequence. Print the first 100 elements of the Fibonacci sequence.
// 9. Define a method named FibonacciRecursion that does the same as the previous method, but uses recursion.
// 10. Define a function that finds the minimum element of an array. Define an array in the main program and print its minimum element.
// 11. Define a function that finds the maximum element of an array. Define an array in the main program and print its maximum element.
// 12. Define a function that returns only the odd elements of an array. Print the returned elements.
// 13. Define a function that sorts an array of integers using bubble sort.
// I. first day
// 1. Hello World
using System.Security.Cryptography.X509Certificates;
Greet("Ilkay");
// 2. Variables, Primitive data Types Literals
// Task 2.1. distance2MoonKm = 384440; // 2.1.1. represent it in hexadecimal 0x5dd90// print it on the console. int.ToString("E");
Console.WriteLine("Test");
int a = 7;
int b = 3;
int speedOfLight = 0xe3; //300000;
Console.WriteLine((float)a/b);
// 3. Operators
// 3.1. Print the remaining fo the division of 15 an 2 15%2
// Task 3.1.
Console.WriteLine(a*b > b*b*a || b + a < a*b);
// 4. Formatted output/ Reading from console
// 4.1. Read the age of a person add 10 and print what would be the age in 10 yeras.
Console.WriteLine("{0,10:C2}", b);
Console.Write("Please, enter your age: ");
string age = Console.ReadLine();
int ageDigit = int.Parse(age);
Console.WriteLine("In 10 years you will be {0}", ageDigit + 10);
// Console.Write("Please, tell me how much money do you have: ");
// 5. Conditional Logic
// 5.1. If the age is greater than 40 print you are old else print you are young
//Console.Write("Please enter your age: ");
//string aaa = Console.ReadLine();
//int age1 = int.Parse(Console.ReadLine());
////if (age1 >= 0 && age1 <= 3)
////{
//// Console.WriteLine("You are a baby");
////}
//if (age1 >= 0 && age1 <=3)
//{
// Console.WriteLine("You are a baby");
//}
//else if (age1 >= 3 && age1 <= 13)
//{
// Console.WriteLine("You are a kid");
//}
//else if (age1 > 13 && age1 <= 18)
//{
// Console.WriteLine("You are teenager!");
//}
//else
//{
// Console.WriteLine("You are an aduld");
//}
//Console.Write("Enter the first letter of your name: ");
//char firstLetter = char.Parse(Console.ReadLine());
//switch (firstLetter)
//{
// case 'S':
// Console.WriteLine("You are a lucki man");
// break;
// case 'D':
// Console.WriteLine("You are a great man");
// break;
// default:
// Console.WriteLine("I don't know what to say");
// break;
//}
// 6. Loops
// 6.1. Print the number from 1 to 100
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);
}
// II Second day of Excercises
//7. Arrays
// 7.1. Create an array of integers double each one of the values and print it.
// Declare an array of 10 Ints assign values and print them on the console
string[] namesOfStudents = new string[] {
"Yaren",
"Darina",
"Aishe",
"Suzana",
"Momchil",
"Ivan...14",
"Stanislava",
"Ilker",
"Ilkay",
"Dean",
"Nikola"
};
Console.WriteLine("Hello Deny!");
int[] numbers = new int[10];
numbers[0] = 10;
numbers[1] = 12;
foreach (var n in numbers)
{
Console.WriteLine(n);
}
Greet("Stanislava");
int number;
do
{
Console.Write("Please enter a number between 1 - 5: ");
number = int.Parse(Console.ReadLine());
} while (number < 1 || number > 5);
// 8. Number systems
Console.WriteLine("2093 to BIN {0}.", Convert.ToString(2093, 2));
Console.WriteLine("2093 to OCT {0}.", Convert.ToString(2093, 8));
Console.WriteLine("2093 to HEX {0}.", Convert.ToString(2093, 16));
// 9. Methods
// 9.1. define method fibonachi that prints the n-th number of Fibbonachi secuence. ANd print the first 100 fibonachies.
// Declare and define a method which grrets. First without formal parameters and returned value. After that with a formal parameter
Console.WriteLine(AddNumbers(34, 54));
static void Greet(string name = "Deny")
{
Console.WriteLine($"Hello {name}!");
}
// Declare and define a function with a returned value which adds two digits
static int AddNumbers(int a, int b)
{
return a + b;
}
static bool IsOdd(int num)
{
return (num % 2 == 1)? true : false;
}
// 10. Recursion
// 10.1. Change the fibbonachi from 9.1. to recursion and do the same print the first 100 fibonnachi numbers
// With the help of ChatGPT create a function factorial
// factorial
// 0! = 1
// n! = (n-1)! * n
static int Factorial(int n)
{
if (n == 0)
{
return 1;
}
else
{
return n * Factorial(n - 1);
}
}
Console.WriteLine(Factorial(3));
static double FactorialIter(int n)
{
double factorial = 1;
for (int i = 2; i <= n; i++)
{
factorial *= i;
}
return factorial;
}
// III. Excercise
// 1. Define a function that finds the min element in array of ints
//int[] nums = {1,2,3,4,5,6,7,8,9};
//void FindLowest()
//{
// int lowest = int.MaxValue;
// for (int i = 0; i < nums.Length; i++)
// {
// int current = nums[i];
// if (current < lowest)
// {
// current = lowest;
// }
// }
// Console.WriteLine( lowest);
//};
//FindLowest();
// Min
static int FindMin(int[] nArray)
{
int min = nArray[0];
foreach (int num in nArray)
{
if (min > num) { min = num; }
}
return min;
}
// Max
static int FindMax(int[] nArray)
{
int max = nArray[0];
foreach (int num in nArray)
{
if (max < num) { max = num; }
}
return max;
}
// Sort
static void BubbleSortDescending(int[] arr)
{
int temp;
for (int i = 0; i < arr.Length - 1; i++)
{
for (int j = 0; j < arr.Length - i - 1; j++)
{
if (arr[j] < arr[j + 1]) // For ascending order, use '>'
{
// Swap the elements
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
// Filter
static int[] FilterOddNumbers(int[] arr)
{
int count = 0;
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] % 2 != 0)
{
count++;
}
}
int[] result = new int[count];
int index = 0;
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] % 2 != 0)
{
result[index] = arr[i];
index++;
}
}
return result;
}
int[] nums = { 23, 29, 354, 432, 765, 89, 90, 87, 9, 10 };
Console.WriteLine("Find Min = {0}", FindMin(nums));
Console.WriteLine("Find Min = {0}", FindMax(nums));
// int[] oddNums = nums.Where(n => n % 2 != 0).ToArray();
int[] oddNums = FilterOddNumbers(nums);
foreach (var num in oddNums)
{
Console.WriteLine(num);
}
BubbleSortDescending(nums);
// Print the sorted array
foreach (var num in nums)
{
Console.WriteLine(num);
}
Comments