Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Globalization;
- using System.Text;
- using System.Threading;
- namespace HelloKristina
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Hello World!");
- // Primitive data types
- byte myByte = 255;
- sbyte mySByte = -128;
- short myShort = 123;// -2^15 2^15 - 1
- ushort myUshort = 65535;
- long myLong = -3424523;
- ulong myUlong = 45435;
- int age1 = 55;
- int age2 = 18;
- int ageResult;
- ageResult = age1 + age2;
- float myFloat = 3.12345645455353453f;
- double myDouble = 12.4353454354353453454353453453453454;
- decimal decimalPI = 3.14159265358979323846m;
- Console.WriteLine(decimalPI); // 3.14159265358979323846
- Console.WriteLine(myFloat);
- Console.WriteLine(myDouble);
- char myChar = 'P';
- myChar = '\u0041'; // myChar = 'A';
- string myString = "Petya";
- bool myBool = true; // false | true
- // Object myObject = 3;
- Console.WriteLine(myChar);
- Console.WriteLine(ageResult);
- // Operators
- int a = 11;
- int b = 2;
- // Arithmetic operators
- Console.WriteLine(a + b);
- Console.WriteLine(a - b);
- Console.WriteLine(a / b);
- Console.WriteLine(a * b);
- Console.WriteLine(a++);
- Console.WriteLine(a);
- Console.WriteLine(++a);
- Console.WriteLine(a % b);
- Console.WriteLine(--a);
- Console.WriteLine(a--);
- Console.WriteLine(2 + (4 / 2 - 4) % 2);
- // Operators for comparison
- Console.WriteLine(a > b);
- Console.WriteLine(a < b);
- Console.WriteLine(a >= b);
- Console.WriteLine(a <= b);
- Console.WriteLine(a == b);
- Console.WriteLine(a != b);
- // Logical operators
- bool x = true;
- bool y = false;
- Console.WriteLine(x && y);
- Console.WriteLine(x || y);
- Console.WriteLine(x ^ y);
- Console.WriteLine(!x);
- // Asignment opertors
- a += 3; // a = a + 3;
- // Bitwise operators
- Console.WriteLine(1 << 1);
- Console.WriteLine(2 >> 1);
- Console.WriteLine(1 | 2);
- Console.WriteLine(1 & 2);
- Console.WriteLine(1 ^ 3);// 2
- string name = "Stoyan";
- string familyName = "Cheresharov";
- // COncatination operator +
- Console.WriteLine(name + " " + familyName + a);
- int test1 = 11;
- int test2 = 2;
- Console.WriteLine(test1 / (float)test2);
- byte petya1 = 4; // unsigned integers 0-255
- sbyte petya2 = -2;
- Console.WriteLine(petya1 + petya2);
- char myTest = (petya1 < petya2) ? 'C' : 'E';
- Console.WriteLine(myTest);
- Console.WriteLine("Hello Emil, Evgeni!");
- // System.Console.Beep(1000, 1000);
- // 3 Writing
- // 3.1 Write
- System.Console.Write("Please enter somethig: ");
- // 3.2 WriteLine
- System.Console.WriteLine("Emil");
- Console.WriteLine("Spas!!!");
- // 1
- Console.WriteLine("The favoritn number of Petya is " + petya1);
- // 2
- Console.WriteLine("Petya has a little lamb! It has {0} legs. And the seconnd favorit number is {1}", petya1, petya2);
- // 3
- Console.WriteLine($"Petya has a little lamb! It has {petya1} legs. And the seconnd favorit number is {petya2}");
- Console.OutputEncoding = Encoding.UTF8;
- Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("bg-Bg");
- // CultureInfo.GetCultureInfo("ro-Ro");
- // CultureInfo.InvariantCulture;
- byte bestNumber = 5;
- Console.WriteLine("Best number = {0}", bestNumber);
- Console.WriteLine("{0,11:C2}|{1,10}",bestNumber, 7);
- Console.WriteLine("{0:F2}", 2345.4545364654);
- decimal spasBalance = 5.05m;
- Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-Gb");
- Console.WriteLine("{0:C2}", spasBalance);
- Console.WriteLine("{0:D20}", 123434566789);
- Console.WriteLine("{0,10:E8}", -1234.5);
- Console.WriteLine("{0,10:F2}", -123.456);
- Console.WriteLine("{0,10:N2}", -1234.56);
- Console.WriteLine("{0,10:P2}", 0.45656);
- Console.WriteLine("{0,10:X5}", 254);
- // Custom Formatting Symbols 0000, ###, %, E0 Е+0 Е-0
- Console.WriteLine("{0:0.00}", 1); //Output: 1,00
- Console.WriteLine("{0:#.##}", 0.234); //Output: ,23
- Console.WriteLine("{0:#####}", 12345.67); //Output: 12346
- Console.WriteLine("{0:(0#) ### ## ##}", 29342525); //Output: (02) 934 25 25
- Console.WriteLine("{0:%##}", 0.234);//Output: %23
- // Standard Formatting Symbols for DateTime
- DateTime d = new DateTime(2018, 12, 12, 11, 05, 22);
- Console.WriteLine("{0:D}", d); // d D
- Console.WriteLine("{0:t}", d); // t T
- Console.WriteLine("{0:Y}", d); // y Y
- // Custom Formatting Symbols for DateTime d, dd, M, MM, yy, yyyy, hh, HH, m, mm, s, ss
- Console.WriteLine("{0:dd/MM/yyyy HH:mm:ss}", d);
- Console.WriteLine("{0:d.MM.yy г.}", d);
- Console.BackgroundColor = ConsoleColor.DarkBlue;
- Console.Clear();
- Console.BackgroundColor = ConsoleColor.Green;
- Console.ForegroundColor = ConsoleColor.Red;
- Console.SetCursorPosition(50, 15); // left top
- Console.WriteLine("Elena");
- Console.BackgroundColor = ConsoleColor.Black;
- Console.Clear();
- Console.ForegroundColor = ConsoleColor.White;
- // Read
- //Console.Write("Please eneter your name: ");
- //int name2 = Console.Read();
- //Console.WriteLine("Welcome {0}!", name2);
- //Console.Write("Please, eneter your name: ");
- //string name2 = Console.ReadLine();
- //Console.WriteLine("Welcome {0}!", name2);
- ////1.
- //Console.Write("Please, enter your age: ");
- //int age = int.Parse(Console.ReadLine()); // 45
- //Console.WriteLine("Your age in 10 years time will be {0}", age + 10);
- //Console.Write("Please, enter your balance: ");
- //decimal balance = decimal.Parse(Console.ReadLine());
- //// 2
- //Console.Write("Please enter int number or something stupid: ");
- //int myVar;
- //if (!int.TryParse(Console.ReadLine(), out myVar))
- //{
- // Console.WriteLine("Please be polite!");
- //}
- // 3
- // int converted = Convert.ToInt32(Console.ReadLine());
- //if (myVar > 5)
- //{
- // Console.WriteLine("myVar is greater than 5!");
- //}
- //else if (myVar < 0 && myVar > -10)
- //{
- // Console.WriteLine("myVar < 0 && myVar > -10");
- //}
- //else
- //{
- // Console.WriteLine("myVar is lower than 5!");
- //}
- //Console.Write("Please, enter your name: ");
- //int firstLetter = Console.Read();
- //switch ((char)firstLetter)
- //{
- // case 'S':
- // Console.WriteLine("Mybe your name is Stoyan");
- // break;
- // case 'E':
- // Console.WriteLine("Mybe your name is Elena");
- // break;
- // default:
- // Console.WriteLine("I give up!");
- // break;
- //}
- // Console.WriteLine(1);
- // Console.WriteLine(2);
- int i = 0;
- while (i < 100)
- {
- Console.WriteLine(i);
- i++;
- }
- int number = 0;
- do
- {
- Console.Write("Please, enter a number between 3 and 30: ");
- number = int.Parse(Console.ReadLine());
- } while (number < 3 || number > 30);
- for (int j = 0; j < 100; j++)
- {
- if (j % 2 != 0)
- {
- // Console.WriteLine(j);
- continue;
- }
- Console.WriteLine(j);
- if (j == 5)
- {
- break;
- }
- }
- int[] numbers = { 2, 3, 5, 7, 11, 13, 17, 19 };
- foreach (int k in numbers)
- {
- Console.Write(" " + k);
- }
- Console.WriteLine();
- string[] students = { "Petyta", "Nadya", "Svetla", "Slavka", "Angela", "Dimitar", "Irina", "Marti", "Spas", "Evgeni", "Elena", "Atanas", "Polina", "Polya", "Georgi", "Emil", "Dimitar", "Simona" };
- foreach (var item in students)
- {
- Console.WriteLine(item);
- }
- int[,] matrix =
- {
- {1, 2, 3, 4}, // row 0 values
- {5, 6, 7, 8}, // row 1 values
- };
- Console.WriteLine(matrix.GetLength(0));
- Console.WriteLine(matrix.GetLength(1));
- int[][] myJaggedArray = {
- new int[] {5, 7, 2},
- new int[] {10, 20, 40},
- new int[] {3, 25},
- new int[] { 1,2,3,4,5,6,78,9}
- };
- int[][,] jaggedOfMulti = new int[2][,];
- // another way to declare jagged array
- int[][] jaggedArray;
- jaggedArray = new int[2][];
- jaggedArray[0] = new int[5];
- jaggedArray[1] = new int[3];
- // IV
- //0 - 9-> base(radix) 10
- //0 - 1-> 2
- //37
- //3 * 10 ^ 1 + 7 * 10 ^ 0 = 3 * 10 + 7 * 1 = 30 + 7 = 37
- //1011
- //1 * 2 ^ 3 + 0 * 2 ^ 2 + 1 * 2 ^ 1 + 1 * 2 ^ 0 = 1 * 8 + 0 + 1 * 2 + 1 * 1 = 11
- //37 : 2 = 18 1
- //18 : 2 = 9 0
- //9 : 2 = 4 1
- //4 : 2 = 2 0
- //2 : 2 = 1 0
- // 1
- //100101
- //1 * 2 ^ 5 + 0 * 2 ^ 4 + 0 * 2 ^ 3 + 1 * 2 ^ 2 + 0 * 2 ^ 1 + 1 * 2 ^ 0 = 1 * 32 + 4 + 1 = 37
- //0 - 9...ABCDEF
- //1A
- //1 * 16 ^ 1 + 10 * 16 ^ 0 = 16 + 10 = 26
- //0001 1010
- //0 - 7
- //17(8)
- //1 * 8 ^ 1 + 7 * 8 ^ 0 = 8 + 7 = 15
- //0010 1110 0101 0101 0101 0101
- //2 E 5 5 5 5
- //a - 10
- //b - 11
- //c - 12
- //d - 13
- //e - 14
- //001 011 100 101 010 101 010 101
- //1 3 4 5 2 5 2 5(8)
- // 9. Methods
- // 0! = 1
- // n! = (n-1)! * n
- // 3! = 1 * 2 * 3
- // 4!
- int factorial = 1;
- for (int f = 1; f < 5; f++)
- {
- factorial *= f;
- }
- Console.WriteLine($"Factorial 4! = {factorial}");
- // 5!
- factorial = 1;
- for (int f = 1; f < 6; f++)
- {
- factorial *= f;
- }
- Console.WriteLine($"Factorial 5! = {factorial}");
- int fn = CalculateFactorial(10);
- Console.WriteLine(fn);
- int[] myInputArray = new int[6];
- InputArray(myInputArray);
- //for (int m = 0; m < myInputArray.Length; m++)
- //{
- // Console.Write("Please, enter myInputArray[{0}] = ", m);
- // myInputArray[m] = int.Parse(Console.ReadLine());
- //}
- //myInputArray = new int[8];
- //for (int m = 0; m < myInputArray.Length; m++)
- //{
- // Console.Write("Please, enter myInputArray[{0}] = ", m);
- // myInputArray[m] = int.Parse(Console.ReadLine());
- //}
- Console.WriteLine(Factorial(100));
- }
- static int CalculateFactorial(int f)
- {
- int factorial = 1;
- for (int i = 1; i <= f; i++)
- {
- factorial *= i;
- }
- return factorial;
- }
- // 0! = 1
- // n! = (n-1)! * n
- static int Factorial(int n)
- {
- if (n == 0) return 1;
- return Factorial(n - 1) * n;
- }
- static void InputArray(int[] myInputArray)
- {
- for (int m = 0; m < myInputArray.Length; m++)
- {
- Console.Write("Please, enter myInputArray[{0}] = ", m);
- myInputArray[m] = int.Parse(Console.ReadLine());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement