Advertisement
wingman007

2016HelloWorld3a

Sep 17th, 2016
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.29 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 HelloWorld3a
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             /*
  14.             Console.WriteLine("Hello world аояьяоао!");
  15.             Console.Beep(500, 1000);
  16.  
  17.             byte age = 53;
  18.             decimal money;
  19.             char firstLetter = 'S';
  20.             string name = "Stoyan";
  21.             bool isMale = true;
  22.  
  23.             money = 2.54m;
  24.  
  25.             firstLetter = 'T';
  26.  
  27.             Console.WriteLine("I am {0} years old.", age);
  28.             Console.WriteLine("I have {0} money!", money);
  29.             Console.WriteLine("I am {1} years old!. The first letter of my name is {0}. ", firstLetter, age);
  30.             Console.WriteLine("My name is {0}", name);
  31.             Console.WriteLine("Am I a man?{0}", isMale);
  32.  
  33.             byte a = 13;
  34.             byte b = 5;
  35.             // 1.
  36.             Console.WriteLine("{0} + {1} = {2}",a, b, a + b);
  37.             Console.WriteLine("{0} - {1} = {2}", a, b, a - b);
  38.             Console.WriteLine("{0} * {1} = {2}", a, b, a * b);
  39.             Console.WriteLine("{0} / {1} = {2}", a, b, a / b);
  40.             Console.WriteLine("{0} % {1} = {2}", a, b, a % b);
  41.             Console.WriteLine("++{0}  = {1}", a, ++a);
  42.  
  43.             // 2. comparison
  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} = {2}", a, b, a <= b);
  47.             Console.WriteLine("{0} >= {1} = {2}", a, b, a >= b);
  48.             Console.WriteLine("{0} == {1} = {2}", a, b, a == b);
  49.             Console.WriteLine("{0} == {1} = {2}", a, b, a != b);
  50.            
  51.             // 3. Boolean
  52.             bool c = true;
  53.             bool d = false;
  54.  
  55.             Console.WriteLine("{0} && {1} = {2}", c, d, c && d);
  56.             Console.WriteLine("{0} || {1} = {2}", c, d, c || d);
  57.             Console.WriteLine("{0} ^ {1} = {2}", c, d, c ^ d);
  58.             Console.WriteLine("!{0} = {1}", c, !c);
  59.  
  60.             // kdjsfhsdkfjh askjfsdk fdkjh fksjh fkjsd
  61.             // a = 5; // a = a + 5;
  62.  
  63.             Console.WriteLine("{0} << 1 {1}", 1, 1 << 1);
  64.             Console.WriteLine("{0} >> 1 {1}", 1, 1 >> 1);
  65.             Console.WriteLine("{0} | {1} = {2}", a, b, a | b);
  66.             Console.WriteLine("{0} & {1} = {2}", a, b, a & b);
  67.             Console.WriteLine("{0} ^ {1} = {2}", a, b, a ^ b);
  68.             Console.WriteLine("~{0} = {1}", a, ~a);
  69.  
  70.             Console.WriteLine("Please, enter your age:");
  71.             string input = Console.ReadLine();
  72.             byte newAge = byte.Parse(input);          
  73.  
  74.             Console.WriteLine("In 10 years you will be {0}", input + 10);
  75.  
  76.             if( newAge <= 18 )
  77.             {
  78.                 Console.WriteLine("You are a teenager!!!");
  79.             }
  80.             else if (newAge > 18 && newAge <= 30)
  81.             {
  82.                 Console.WriteLine("You are in a golden age!");
  83.             }
  84.             else
  85.             {
  86.                 Console.WriteLine("You are an adult!");            
  87.             }
  88.  
  89.             switch (newAge)
  90.             {
  91.                 case 22 :
  92.                 case 23 :
  93.                     Console.WriteLine("You are 23 years old. You are very sick person!");
  94.                     break;
  95.                 default :
  96.                     Console.WriteLine("I don't know what to say!");
  97.                     break;
  98.             }
  99.             */
  100.             //Console.WriteLine(1);
  101.             //Console.WriteLine(2);
  102.             //Console.WriteLine(3);
  103.  
  104.             int i = 1;
  105.             while (i <= 10)
  106.             {
  107.                 if (i == 5) break;
  108.                 Console.WriteLine(i);
  109.                 i++;
  110.             }
  111.  
  112.             i = 11;
  113.             do
  114.             {
  115.                 Console.WriteLine("do-while: {0}", i);
  116.                 i++;
  117.             } while (i <= 10);
  118.  
  119.             /*
  120.             string choice = "0";
  121.             do
  122.             {
  123.                 Console.Clear();
  124.                 Console.WriteLine("Моля изберете номер на рецепта:");
  125.                 Console.WriteLine("1. Пържени яйца");
  126.                 Console.WriteLine("2. Пиле с ориз");
  127.                 Console.WriteLine("3. фасул");
  128.                 Console.WriteLine("4. Изход от програмата");
  129.                
  130.                 choice = Console.ReadLine();
  131.                 if (choice == "4") break;
  132.  
  133.                 if (choice == "1")
  134.                 {
  135.                     Console.Clear();
  136.                     Console.WriteLine("За да се върнеш в основното меню натисни кой да е клавиш и после Enter");
  137.                     Console.WriteLine("За да си опържеш яйца...");
  138.                     Console.ReadLine();
  139.                 }
  140.  
  141.             }while(true);
  142.             */
  143.  
  144.  
  145.             for (i = 0; i < 10; i++)
  146.             {
  147.                 if (i % 2 != 0) continue;
  148.                 // if (i % 2 == 0)
  149.                 //{
  150.                 Console.WriteLine("for even {0}", i);
  151.                 //}
  152.             }
  153.  
  154.             string[] studentNames = { "Robeta", "Mirela", "Nikola",
  155.                                         "Adrian", "Mitko", "Milen", "Sabrin",
  156.                                         "Valentin", "Ivan", "Stafan", "Nora",
  157.                                         "Dani", "Konstantin", "Silvestar", "Mirela"};
  158.  
  159.             foreach (string name in studentNames)
  160.             {
  161.                 Console.WriteLine(name);
  162.             }
  163.  
  164.             int[] myArray;
  165.             myArray = new int[5];
  166.             myArray[4] = 45;
  167.  
  168.             // 2.
  169.             // int[] myArray = new int[5];
  170.  
  171.            
  172.             // 3.
  173.             // int[] myArray = {0, 0, 0, 0, 45}
  174.  
  175.             for (i = 0; i < myArray.Length; i++)
  176.             {
  177.                 Console.WriteLine("myArray[{0}] = {1}", i, myArray[i]);
  178.             }
  179.  
  180.  
  181.             //string[,] positionsOfTheStudents;
  182.             //positionsOfTheStudents = new string[3, 8];
  183.             //positionsOfTheStudents[0, 0] = "Roberta";
  184.            
  185.             string[,] positionsOfTheStudents = {
  186.                    {"Roberta", "Mirela","Nikola","","","Adrian", "","Mitko"},
  187.                    {"Milen", "Sabrin","","","Ivan","", "","Stafan"},
  188.                    {"Nora", "Dani","","Konstantin","Silvestar","", "","Mirela"}
  189.             };
  190.  
  191.             for (i = 0; i < positionsOfTheStudents.GetLength(0); i++)
  192.             {
  193.                 for (int j = 0; j < positionsOfTheStudents.GetLength(1); j++)
  194.                 {
  195.                     Console.WriteLine("positionsOfTheStudents[{0},{1}] = {2}", i, j, positionsOfTheStudents[i,j]);
  196.                 }
  197.             }
  198.  
  199.             int[][] jaggedArray;
  200.             jaggedArray = new int[2][];
  201.             jaggedArray[0] = new int[8];
  202.             jaggedArray[1] = new int[5];
  203.  
  204.             byte result = 148;
  205.  
  206.             Console.WriteLine(Convert.ToString(result, 2).PadLeft(16, '0'));
  207.             /*
  208.             for (i = 0; i < 10; i++)
  209.             {
  210.                 Console.Write('*');
  211.             }
  212.             Console.WriteLine();
  213.             for (i = 0; i < 20; i++)
  214.             {
  215.                 Console.Write('^');
  216.             }
  217.  
  218.             */
  219.  
  220.             Console.WriteLine(createString(20));
  221.             Console.WriteLine(createString(10, '^'));
  222.  
  223.             Console.WriteLine("factorial(3) = {0}", factorial(3));
  224.             Console.WriteLine("factorial(3) = {0}", factorialIteration(3));
  225.  
  226.         }
  227.  
  228.         static string createString(int n, char c = '*')
  229.         {
  230.             string temp = "";
  231.             for (int i = 0; i < n; i++)
  232.             {
  233.                 temp += c;
  234.             }
  235.             return temp;
  236.         }
  237.  
  238.         static int factorial(int n)
  239.         {
  240.             if (n == 0) return 1;
  241.             return factorial(n - 1) * n;
  242.         }
  243.  
  244.         static int factorialIteration(int n)
  245.         {
  246.             if (n == 0) return 1;
  247.             int temp = 1;
  248.             for (int i = 1; i <= n; i++)
  249.             {
  250.                 temp *= i; // temp = temp * i;
  251.             }
  252.             return temp;
  253.         }
  254.  
  255.     }
  256. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement