Advertisement
wingman007

IntroC#_loops_arrays_decimal_methods_recursion_1b

Sep 17th, 2014
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.90 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.             int age = 50;
  14.             decimal money = 2.544234342342342342342342342342423M;
  15.             char firstLetter = 'S'; // '\u0fff';
  16.             bool isMail = true;
  17.  
  18.             int nextYear = (age + 1) * 8;
  19.  
  20.             bool result = 1 + 4 * 5 > 34 % 5 + 5 - 6 && 21321 % 4 - 6 <= 32423 % 6 + 4;
  21.  
  22.             string name = "Stoyan";
  23.             object myObject = 5;
  24.             Console.WriteLine("Hello World! And my age: " + age);
  25.             Console.WriteLine("I have : " + money);
  26.             Console.WriteLine("The first letter of my name is : " + firstLetter);
  27.             Console.WriteLine(isMail);
  28.             Console.WriteLine(name);
  29.             Console.WriteLine(nextYear);
  30.             Console.WriteLine(result);
  31.  
  32.             Console.WriteLine("Please enter your age:");
  33.             string age1 = Console.ReadLine();
  34.             Console.WriteLine("{1}You have entered: {0} ", age1, age);
  35.  
  36.             int ageConverted = int.Parse(age1);
  37.  
  38.             if (ageConverted < 20)
  39.             {
  40.                 Console.WriteLine("You are an teenager");
  41.             }
  42.             else if (ageConverted >= 20 && ageConverted < 30)
  43.             {
  44.                 Console.WriteLine("You are in your twentees");
  45.             }
  46.             else {
  47.                 Console.WriteLine("I don't know what to say");
  48.             }
  49.  
  50.             switch (ageConverted) {
  51.                 case 10:
  52.                 case 20:
  53.                     Console.WriteLine("perfect age");
  54.                     break;
  55.                 case 30:
  56.                     Console.WriteLine("Very nice");
  57.                     break;
  58.                 default :
  59.                     Console.WriteLine("You are not 20 or 30 years old. I don't know.");
  60.                     break;
  61.             }
  62.  
  63.             Console.WriteLine(1);
  64.             Console.WriteLine(2);
  65.             Console.WriteLine(3);
  66.             // ...
  67.  
  68.             int i = 1;
  69.             while ( i <= 10) {
  70.                 if (i == 5) break;
  71.                 Console.WriteLine("while: {0}: ", i);
  72.                 i++;
  73.             }
  74.  
  75.             Console.WriteLine("Please select [1-4]:");
  76.             Console.WriteLine("1. List partitions");
  77.             Console.WriteLine("2. Create a partiono");
  78.             Console.WriteLine("3. Delete partition");
  79.             Console.WriteLine("4. Exit");
  80.            
  81.             string choice = "";
  82.             while (true) {
  83.                 choice = Console.ReadLine();
  84.                 // ... do somethign smart
  85.                 // if (choice == "4") {
  86.                 if (int.Parse(choice) == 4)
  87.                 {
  88.                     break;
  89.                 }
  90.             }
  91.  
  92.             i = 11;
  93.             do {
  94.                 Console.WriteLine("do-while: {0}", i);
  95.                 i++;
  96.             } while(i <= 10);
  97.  
  98.  
  99.             for (i = 0; i < 10; i++) {
  100.                 if (i % 2 != 1) continue;
  101.                 Console.WriteLine("for {0}", i);
  102.             }
  103.  
  104.             string[] group1b = { "Georgi", "Ivan", "Georgi", "Dimitar", "Daniel", "Maria", "Angel", "Stefan", "Dean"};
  105.  
  106.             foreach (string namestr in group1b) {
  107.                 Console.WriteLine(namestr);
  108.             }
  109.  
  110.             for (i = 0; i < 10; i++) {
  111.                 for (int j = 0; j < i; j++) {
  112.                     Console.Write("*");
  113.                 }
  114.                 Console.WriteLine();
  115.             }
  116.             /*
  117.             int[] myArray;
  118.             myArray = new int[5];
  119.             myArray[4] = 45;
  120.             */
  121.  
  122.             // 2)
  123.             // int[] myArray = { 32, 45, 67, 890 };
  124.  
  125.             int[] myArray = new int[3] { 23, 45, 46 };
  126.  
  127.             for (i = 0; i < myArray.Length; i++) {
  128.                 Console.WriteLine("myArray[{0}] = {1}", i, myArray[i]);
  129.             }
  130.  
  131.             string[,] positionsOfTheStudents = {
  132.                    {"Hristo", "Georgi","","","Ivan","", "","Georgi"},
  133.                    {"Dimitar", "Daniel","","Maria","","", "","Angel"},
  134.                    {"Stefan", "","","Dean","","", "",""}
  135.             };
  136.  
  137.             for (i = 0; i < positionsOfTheStudents.GetLength(0); i++)
  138.             {
  139.                 Console.Write("Red {0}: ", i);
  140.                 for (int j = 0; j < positionsOfTheStudents.GetLength(1); j++)
  141.                 {
  142.                     Console.Write(" {0}", positionsOfTheStudents[i, j]);
  143.                 }
  144.                 Console.WriteLine();
  145.             }
  146.  
  147.             int[][] jaggedArray;
  148.             jaggedArray = new int[2][];
  149.             jaggedArray[0] = new int[8];
  150.             jaggedArray[1] = new int[5];
  151.  
  152.             /*
  153.             string temp = "";
  154.             for (i = 0; i < 15; i++) {
  155.                 temp += "*";
  156.             }
  157.             Console.WriteLine(temp);
  158.  
  159.             temp = "";
  160.             for (i = 0; i < 5; i++)
  161.             {
  162.                 temp += "@";
  163.             }
  164.             Console.WriteLine(temp);
  165.             */
  166.  
  167.             Console.WriteLine(createString(12));
  168.             Console.WriteLine(createString(10));
  169.             Console.WriteLine(createString(5));
  170.             Console.WriteLine(createString(15, "@"));
  171.             Console.WriteLine(createString(15, "@", "Stoyan", "Ivan", "blah blah"));
  172.             Console.WriteLine(createString());
  173.  
  174.             Console.WriteLine("Factorial from {0} = {1}", 6, factorial(6));
  175.             Console.WriteLine("Factorial from {0} = {1}", 6, factorialIteration(6));
  176.  
  177.             for (i = 0; i < 10; i++)
  178.             {
  179.                 Console.WriteLine("Fibonacci {0} => {1}", i, fibonacci(i));
  180.             }
  181.  
  182.         }
  183.  
  184.         static string createString(int strLength, string str = "*", params string[] par)
  185.         {
  186.             string temp = "";
  187.             for (int i = 0; i < strLength; i++)
  188.             {
  189.                 temp += str;
  190.             }
  191.  
  192.             foreach (string name in par) {
  193.                 Console.WriteLine(name);
  194.             }
  195.  
  196.             return temp;
  197.         }
  198.  
  199.         static string createString() {
  200.             return "Hahahaha";
  201.         }
  202.  
  203.         /*
  204.         static string createString(int sadh, string erwrew = "*", params string[] par)
  205.         {
  206.             return "Error!!!";
  207.         }
  208.         */
  209.  
  210.         static int factorial(int n) {
  211.             if (n == 0) return 1;
  212.             return factorial(n - 1) * n;
  213.         }
  214.  
  215.         static int factorialIteration(int n)
  216.         {
  217.             var factorial = 1;
  218.             for (int i = 1; i <= n; i++)
  219.             {
  220.                 factorial *= i;
  221.             }
  222.  
  223.             return factorial;
  224.         }
  225.  
  226.         static int fibonacci(int n) {
  227.             if (n <= 2) return 1;
  228.             return fibonacci(n - 2) + fibonacci(n - 1);
  229.         }
  230.     }
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement