Advertisement
wingman007

2016HelloWorld1b

Sep 17th, 2016
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace HelloWorld1b
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("Hello World Stoyan!");
  14.             Console.WriteLine(DateTime.Now);
  15.  
  16.             long age = 52L;
  17.             double money = 2.54;
  18.             char firstLetter = 'S';
  19.             string name = "Stoyan";
  20.             bool isMale = true;
  21.  
  22.             // paradox
  23.             double sum = 0.1 + 0.2;
  24.             Console.WriteLine(sum == 0.3); // False
  25.  
  26.             Console.WriteLine("I am {0} years old!", age);
  27.             Console.WriteLine("I have {0} USD", money);
  28.             Console.WriteLine("The first letter of my name is {0}", firstLetter);
  29.             Console.WriteLine("My name is {0}", name);
  30.             Console.WriteLine("Is male? {0}", isMale);
  31.             Console.WriteLine("I have {2,10:c2} USD. My name is {0}. I am {1} years old!. ", name, age, money);
  32.  
  33.             Console.WriteLine("Plese, enter your age:");
  34.             string input = Console.ReadLine();
  35.             age = byte.Parse(input);
  36.             Console.WriteLine("Your age is {0}. In 10 years you will be {1}.", input, age + 10);
  37.  
  38.             byte a = 13;
  39.             byte b = 5;
  40.             // 1.
  41.             Console.WriteLine("{0} + {1} = {2}", a, b, a + b);
  42.             Console.WriteLine("{0} - {1} = {2}", a, b, a - b);
  43.             Console.WriteLine("{0} * {1} = {2}", a, b, a * b);
  44.             Console.WriteLine("{0} / {1} = {2}", a, b, a / b);
  45.             Console.WriteLine("{0} % {1} = {2}", a, b, a % b);
  46.             Console.WriteLine("++{0}  = {1}", a, ++a);
  47.  
  48.             // 2. comparison
  49.             Console.WriteLine("{0} < {1} = {2}", a, b, a < b);
  50.             Console.WriteLine("{0} > {1} = {2}", a, b, a > b);
  51.             Console.WriteLine("{0} <= {1} = {2}", a, b, a <= b);
  52.             Console.WriteLine("{0} >= {1} = {2}", a, b, a >= b);
  53.             Console.WriteLine("{0} == {1} = {2}", a, b, a == b);
  54.             Console.WriteLine("{0} == {1} = {2}", a, b, a != b);
  55.  
  56.             // 3. Boolean
  57.             bool c = true;
  58.             bool d = false;
  59.  
  60.             Console.WriteLine("{0} && {1} = {2}", c, d, c && d);
  61.             Console.WriteLine("{0} || {1} = {2}", c, d, c || d);
  62.             Console.WriteLine("{0} ^ {1} = {2}", c, d, c ^ d);
  63.             Console.WriteLine("!{0} = {1}", c, !c);
  64.  
  65.             if (age <= 20)
  66.             {
  67.                 Console.WriteLine("You are a teenager!");
  68.             }
  69.             else if (age > 20 && age <= 30)
  70.             {
  71.                 Console.WriteLine("You are an a golden age!");
  72.             }
  73.             else {
  74.                 Console.WriteLine("I don't know what to say!");
  75.             }
  76.  
  77.             switch (age)
  78.             {
  79.                 case 21:
  80.                 case 22:
  81.                     Console.WriteLine("You are very sick!");
  82.                     break;
  83.                 case 23:
  84.                     Console.WriteLine("You are blue!");
  85.                     break;
  86.                 default :
  87.                     Console.WriteLine("I don't know what to say!");
  88.                     break;
  89.             }
  90.  
  91.             byte result = 23;
  92.             Console.WriteLine(Convert.ToString(result, 2).PadLeft(16, '0'));
  93.             // 0000000000110011
  94.             /*
  95.             Console.WriteLine(1);
  96.             Console.WriteLine(2);
  97.             Console.WriteLine(3);
  98.             Console.WriteLine(4);
  99.             Console.WriteLine(5);
  100.             */
  101.  
  102.             int i = 1;
  103.             /*
  104.             while (i <= 1000)
  105.             {
  106.                 if (i == 5) break;
  107.                 Console.WriteLine(i);
  108.                 i++;
  109.             }
  110.  
  111.             Console.WriteLine("Please choose:");
  112.             Console.WriteLine("1. List the partitions");
  113.             Console.WriteLine("2. Create a partition");
  114.             Console.WriteLine("3. Delete partiotion");
  115.             Console.WriteLine("4. Exit");
  116.             string choice = "";
  117.             while (true)
  118.             {
  119.                 //... do something smart
  120.                 choice = Console.ReadLine();
  121.                 if (choice == "4")
  122.                 {
  123.                     break;
  124.                 }
  125.             }
  126.             */
  127.             /*
  128.             string choice = "";
  129.             i = 1;
  130.             do
  131.             {
  132.                 Console.Clear();
  133.                 Console.WriteLine("Моля изберете:");
  134.                 Console.WriteLine("1. Пържени яйца");
  135.                 Console.WriteLine("2. Фасул");
  136.                 Console.WriteLine("3. Пиле с ориз");
  137.                 Console.WriteLine("4. Изход");
  138.                 // Console.WriteLine("do-while: {0}!", i);
  139.                 choice = Console.ReadLine();
  140.                 if (choice == "4")
  141.                 {
  142.                     break;
  143.                 }
  144.                
  145.                 if (choice == "1") {
  146.                     Console.Clear();
  147.                     Console.WriteLine("Натиснете който и да е клавиш, за да се върнете към главното меню!");
  148.                     Console.WriteLine("За да си опържиш яийца ...");
  149.                     choice = Console.ReadLine();
  150.                 }
  151.              
  152.                 //if (choice == "1")
  153.                 //{
  154.                 //    do
  155.                 //    {
  156.                 //        Console.Clear();
  157.                 //        Console.WriteLine("Натиснете 4 за да се върнете към главното меню!");
  158.                 //        Console.WriteLine("За да си опържиш яийца ...");
  159.                 //        choice = Console.ReadLine();
  160.                 //        if (choice == "4") break;
  161.                 //    } while (true);
  162.  
  163.                 //}
  164.            
  165.             }while(true);
  166.             */
  167.             for (i = 0; i < 100; i++)
  168.             {
  169.                 if (i % 2 == 1) continue;
  170.                 if (i % 2 == 0)
  171.                 {
  172.                     Console.WriteLine("for {0}", i);
  173.                 }
  174.  
  175.             }
  176.            
  177.             string[] names = { "Marina", "Mitko", "Plamen", "Mitko", "Dani", "Victor", "Valentin", "Vasko", "Yusein", "Sevelina", "Ivan"};
  178.  
  179.             foreach (string studentName in names)
  180.             {
  181.                 Console.WriteLine(studentName);
  182.             }
  183.  
  184.             // int[] myArray;
  185.             // myArray = new int[5];
  186.             // int[] myArray = new int[5];
  187.  
  188.             int[] myArray = { 0,22,0,0,45};
  189.  
  190.             // myArray[1] = 22;
  191.             // myArray[4] = 45;
  192.  
  193.             for (i = 0; i < myArray.Length; i++)
  194.             {
  195.                 Console.WriteLine("myArray[{0}] = {1}", i, myArray[i]);
  196.             }
  197.  
  198.             string[,] positionsOfTheStudents = {
  199.                    {"Marina", "Mitko","","Plamen","","Mitko", "","Dani"},
  200.                    {"Victor", "Valentin","","Vasil","Yusein","", "","Sevelina"},
  201.                    {"", "","","","Ivan","", "",""}
  202.             };
  203.  
  204.  
  205.             for (i = 0; i < positionsOfTheStudents.GetLength(0); i++)
  206.             {
  207.                 for (int j = 0; j < positionsOfTheStudents.GetLength(1); j++)
  208.                 {
  209.                     Console.WriteLine("positionsOfTheStudents[{0}{1}] = {2}", i, j, positionsOfTheStudents[i,j]);
  210.                 }
  211.             }
  212.  
  213.             int[][] jaggedArray;
  214.             jaggedArray = new int[2][];
  215.             jaggedArray[0] = new int[8];
  216.             jaggedArray[1] = new int[5];
  217.  
  218.             int resultTest = 2040;
  219.             Console.WriteLine(Convert.ToString(resultTest, 2).PadLeft(16, '0'));
  220.             Console.WriteLine("{0,10:X}", resultTest);
  221.             /*
  222.             for (i = 0; i < 10; i++)
  223.             {
  224.                 Console.Write('*');
  225.             }
  226.             Console.WriteLine();
  227.             for (i = 0; i < 20; i++)
  228.             {
  229.                 Console.Write('\\');
  230.             }
  231.             Console.WriteLine();
  232.             for (i = 0; i < 80; i++)
  233.             {
  234.                 Console.Write('^');
  235.             }
  236.             */
  237.  
  238.             Console.WriteLine(createString(8, '\\', "Stoyan","Mitko"));
  239.  
  240.             Console.WriteLine("factorial(6) = {0}", factorial(6));
  241.             Console.WriteLine(factorialIteration(6));
  242.  
  243.             Console.WriteLine("Prime numbers:");
  244.             bool isPrime = true;
  245.             for (i = 2; i < 100; i++)
  246.             {
  247.                 isPrime = true;
  248.                 for (int j = 2; j < i; j++)
  249.                 {
  250.                     // if (i % j == 0)
  251.                     if (i % Math.Sqrt(j) == 0) // better
  252.                     {
  253.                         isPrime = false;
  254.                         break;
  255.                     }  
  256.                 }
  257.                 if (isPrime) {
  258.                     Console.WriteLine(i);
  259.                 }
  260.             }
  261.  
  262.             // Pine Tree
  263.             Console.WriteLine("Pine Tree");
  264.             int size = 80;
  265.             for (i = 0; i < size; i++)
  266.             {
  267.                 if (i % 2 == 0) continue;
  268.                 for (int k = (size - i) / 2; k > 0; k--)
  269.                 {
  270.                     Console.Write(" ");
  271.                 }
  272.                 for (int j = 0; j < i; j++)
  273.                 {
  274.                     Console.Write("*");
  275.                 }
  276.                 Console.WriteLine();
  277.             }
  278.  
  279.  
  280.             Console.WriteLine("The number 0xfabc = {0,10:d} ", 0xfabc);
  281.             Console.WriteLine("The number 64188 = {0,10:x}", 64188);
  282.  
  283.         }
  284.  
  285.         static string createString(int n, char c = '*', params string[] extra)
  286.         {
  287.             string temp = "";
  288.             if (extra.Length > 0 && extra[0] != null)
  289.             {
  290.                 for (int i = 0; i < extra.Length; i++ )
  291.                 {
  292.                     temp += extra[i];
  293.                 }    
  294.             }
  295.             for (int i = 0; i < n; i++ )
  296.             {
  297.                 temp += c;
  298.             }
  299.             return temp;
  300.         }
  301.  
  302.         static int factorial(int n)
  303.         {
  304.             if (n == 0) return 1;
  305.             return factorial(n - 1) * n;
  306.         }
  307.  
  308.         static int factorialIteration(int n)
  309.         {
  310.             int temp = 1;
  311.             for (int i = 1; i <= n; i++)
  312.             {
  313.                 temp *= i;
  314.             }
  315.             return temp;
  316.         }
  317.  
  318.  
  319.  
  320.     }
  321. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement