Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace HelloWorld1b
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Hello World Stoyan!");
- Console.WriteLine(DateTime.Now);
- long age = 52L;
- double money = 2.54;
- char firstLetter = 'S';
- string name = "Stoyan";
- bool isMale = true;
- // paradox
- double sum = 0.1 + 0.2;
- Console.WriteLine(sum == 0.3); // False
- Console.WriteLine("I am {0} years old!", age);
- Console.WriteLine("I have {0} USD", money);
- Console.WriteLine("The first letter of my name is {0}", firstLetter);
- Console.WriteLine("My name is {0}", name);
- Console.WriteLine("Is male? {0}", isMale);
- Console.WriteLine("I have {2,10:c2} USD. My name is {0}. I am {1} years old!. ", name, age, money);
- Console.WriteLine("Plese, enter your age:");
- string input = Console.ReadLine();
- age = byte.Parse(input);
- Console.WriteLine("Your age is {0}. In 10 years you will be {1}.", input, age + 10);
- byte a = 13;
- byte b = 5;
- // 1.
- Console.WriteLine("{0} + {1} = {2}", a, b, a + b);
- Console.WriteLine("{0} - {1} = {2}", a, b, a - b);
- Console.WriteLine("{0} * {1} = {2}", a, b, a * b);
- Console.WriteLine("{0} / {1} = {2}", a, b, a / b);
- Console.WriteLine("{0} % {1} = {2}", a, b, a % b);
- Console.WriteLine("++{0} = {1}", a, ++a);
- // 2. comparison
- Console.WriteLine("{0} < {1} = {2}", a, b, a < b);
- Console.WriteLine("{0} > {1} = {2}", a, b, a > b);
- Console.WriteLine("{0} <= {1} = {2}", a, b, a <= b);
- Console.WriteLine("{0} >= {1} = {2}", a, b, a >= b);
- Console.WriteLine("{0} == {1} = {2}", a, b, a == b);
- Console.WriteLine("{0} == {1} = {2}", a, b, a != b);
- // 3. Boolean
- bool c = true;
- bool d = false;
- Console.WriteLine("{0} && {1} = {2}", c, d, c && d);
- Console.WriteLine("{0} || {1} = {2}", c, d, c || d);
- Console.WriteLine("{0} ^ {1} = {2}", c, d, c ^ d);
- Console.WriteLine("!{0} = {1}", c, !c);
- if (age <= 20)
- {
- Console.WriteLine("You are a teenager!");
- }
- else if (age > 20 && age <= 30)
- {
- Console.WriteLine("You are an a golden age!");
- }
- else {
- Console.WriteLine("I don't know what to say!");
- }
- switch (age)
- {
- case 21:
- case 22:
- Console.WriteLine("You are very sick!");
- break;
- case 23:
- Console.WriteLine("You are blue!");
- break;
- default :
- Console.WriteLine("I don't know what to say!");
- break;
- }
- byte result = 23;
- Console.WriteLine(Convert.ToString(result, 2).PadLeft(16, '0'));
- // 0000000000110011
- /*
- Console.WriteLine(1);
- Console.WriteLine(2);
- Console.WriteLine(3);
- Console.WriteLine(4);
- Console.WriteLine(5);
- */
- int i = 1;
- /*
- while (i <= 1000)
- {
- if (i == 5) break;
- Console.WriteLine(i);
- i++;
- }
- Console.WriteLine("Please choose:");
- Console.WriteLine("1. List the partitions");
- Console.WriteLine("2. Create a partition");
- Console.WriteLine("3. Delete partiotion");
- Console.WriteLine("4. Exit");
- string choice = "";
- while (true)
- {
- //... do something smart
- choice = Console.ReadLine();
- if (choice == "4")
- {
- break;
- }
- }
- */
- /*
- string choice = "";
- i = 1;
- do
- {
- Console.Clear();
- Console.WriteLine("Моля изберете:");
- Console.WriteLine("1. Пържени яйца");
- Console.WriteLine("2. Фасул");
- Console.WriteLine("3. Пиле с ориз");
- Console.WriteLine("4. Изход");
- // Console.WriteLine("do-while: {0}!", i);
- choice = Console.ReadLine();
- if (choice == "4")
- {
- break;
- }
- if (choice == "1") {
- Console.Clear();
- Console.WriteLine("Натиснете който и да е клавиш, за да се върнете към главното меню!");
- Console.WriteLine("За да си опържиш яийца ...");
- choice = Console.ReadLine();
- }
- //if (choice == "1")
- //{
- // do
- // {
- // Console.Clear();
- // Console.WriteLine("Натиснете 4 за да се върнете към главното меню!");
- // Console.WriteLine("За да си опържиш яийца ...");
- // choice = Console.ReadLine();
- // if (choice == "4") break;
- // } while (true);
- //}
- }while(true);
- */
- for (i = 0; i < 100; i++)
- {
- if (i % 2 == 1) continue;
- if (i % 2 == 0)
- {
- Console.WriteLine("for {0}", i);
- }
- }
- string[] names = { "Marina", "Mitko", "Plamen", "Mitko", "Dani", "Victor", "Valentin", "Vasko", "Yusein", "Sevelina", "Ivan"};
- foreach (string studentName in names)
- {
- Console.WriteLine(studentName);
- }
- // int[] myArray;
- // myArray = new int[5];
- // int[] myArray = new int[5];
- int[] myArray = { 0,22,0,0,45};
- // myArray[1] = 22;
- // myArray[4] = 45;
- for (i = 0; i < myArray.Length; i++)
- {
- Console.WriteLine("myArray[{0}] = {1}", i, myArray[i]);
- }
- string[,] positionsOfTheStudents = {
- {"Marina", "Mitko","","Plamen","","Mitko", "","Dani"},
- {"Victor", "Valentin","","Vasil","Yusein","", "","Sevelina"},
- {"", "","","","Ivan","", "",""}
- };
- for (i = 0; i < positionsOfTheStudents.GetLength(0); i++)
- {
- for (int j = 0; j < positionsOfTheStudents.GetLength(1); j++)
- {
- Console.WriteLine("positionsOfTheStudents[{0}{1}] = {2}", i, j, positionsOfTheStudents[i,j]);
- }
- }
- int[][] jaggedArray;
- jaggedArray = new int[2][];
- jaggedArray[0] = new int[8];
- jaggedArray[1] = new int[5];
- int resultTest = 2040;
- Console.WriteLine(Convert.ToString(resultTest, 2).PadLeft(16, '0'));
- Console.WriteLine("{0,10:X}", resultTest);
- /*
- for (i = 0; i < 10; i++)
- {
- Console.Write('*');
- }
- Console.WriteLine();
- for (i = 0; i < 20; i++)
- {
- Console.Write('\\');
- }
- Console.WriteLine();
- for (i = 0; i < 80; i++)
- {
- Console.Write('^');
- }
- */
- Console.WriteLine(createString(8, '\\', "Stoyan","Mitko"));
- Console.WriteLine("factorial(6) = {0}", factorial(6));
- Console.WriteLine(factorialIteration(6));
- Console.WriteLine("Prime numbers:");
- bool isPrime = true;
- for (i = 2; i < 100; i++)
- {
- isPrime = true;
- for (int j = 2; j < i; j++)
- {
- // if (i % j == 0)
- if (i % Math.Sqrt(j) == 0) // better
- {
- isPrime = false;
- break;
- }
- }
- if (isPrime) {
- Console.WriteLine(i);
- }
- }
- // Pine Tree
- Console.WriteLine("Pine Tree");
- int size = 80;
- for (i = 0; i < size; i++)
- {
- if (i % 2 == 0) continue;
- for (int k = (size - i) / 2; k > 0; k--)
- {
- Console.Write(" ");
- }
- for (int j = 0; j < i; j++)
- {
- Console.Write("*");
- }
- Console.WriteLine();
- }
- Console.WriteLine("The number 0xfabc = {0,10:d} ", 0xfabc);
- Console.WriteLine("The number 64188 = {0,10:x}", 64188);
- }
- static string createString(int n, char c = '*', params string[] extra)
- {
- string temp = "";
- if (extra.Length > 0 && extra[0] != null)
- {
- for (int i = 0; i < extra.Length; i++ )
- {
- temp += extra[i];
- }
- }
- for (int i = 0; i < n; i++ )
- {
- temp += c;
- }
- return temp;
- }
- static int factorial(int n)
- {
- if (n == 0) return 1;
- return factorial(n - 1) * n;
- }
- static int factorialIteration(int n)
- {
- int temp = 1;
- for (int i = 1; i <= n; i++)
- {
- temp *= i;
- }
- return temp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement