Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Numerics;
- class LoopsDemos
- {
- static void Main()
- {
- /*
- //int n = int.Parse(Console.ReadLine());
- //int i = 0; // initialization
- //while (i < n) // condition
- //{
- // Console.WriteLine(i);
- // i++; // update
- //}
- */
- /*
- int n = int.Parse(Console.ReadLine());
- int i = 0; // initialization
- int sum = 0;
- while (i <= n) // condition
- {
- sum += i;
- i++; // update
- }
- Console.WriteLine(sum);
- */
- /*
- int n = int.Parse(Console.ReadLine());
- // int i = 0; // initialization
- // int sum = 0;
- BigInteger sum = 0;
- while (n > 0) // condition
- {
- checked
- {
- sum += n;
- }
- n--; // update
- }
- Console.WriteLine(sum);
- */
- /*
- int n = int.Parse(Console.ReadLine());
- int i = 2;
- bool isprime = true;
- while (i < n)
- {
- if (n % i == 0)
- {
- isprime = false;
- break;
- }
- i++;
- }
- Console.WriteLine("the number {0} is prime: {1}", n, isprime);
- */
- /*
- int n = int.Parse(Console.ReadLine());
- int i = 2;
- int maxDivider = (int)Math.Sqrt(n);
- bool isPrime = true;
- while (i <= maxDivider)
- {
- if (n % i == 0)
- {
- isPrime = false;
- break;
- }
- i++;
- }
- Console.WriteLine("The number {0} is prime: {1}", n, isPrime);
- */
- /*
- int n = int.Parse(Console.ReadLine());
- int i = 2;
- int maxDivider = (int)Math.Sqrt(n);
- bool isPrime = true;
- while (isPrime && i <= maxDivider)
- {
- if (n % i == 0)
- {
- isPrime = false;
- // break;
- }
- i++;
- }
- Console.WriteLine("The number {0} is prime: {1}", n, isPrime);
- */
- /*
- Random rand = new Random();
- int n = rand.Next(1, 10);
- int i = 0;
- while (i < n)
- {
- Console.WriteLine("i = {0} n = {1}", i, n);
- i++;
- }
- */
- /*
- // factorial 0!= 1 n! = (n-1)!*n;
- int n = int.Parse(Console.ReadLine());
- int factorial = 1;
- while (n > 0)
- {
- checked
- {
- factorial *= n--;
- }
- }
- Console.WriteLine(factorial);
- */
- /*
- int n = int.Parse(Console.ReadLine());
- BigInteger factorial = 1;
- while (n > 0)
- {
- checked
- {
- factorial *= n--;
- }
- }
- Console.WriteLine(factorial);
- */
- /* This is not working factorial 0
- int n = int.Parse(Console.ReadLine());
- BigInteger factorial = 1;
- do
- {
- checked
- {
- factorial *= n--;
- }
- } while (n > 0);
- Console.WriteLine(factorial);
- */
- /*
- string numberAsString = Console.ReadLine();
- int n = Convert.ToInt32(numberAsString);
- int factorial = 1;
- if (n != 0)
- {
- do
- {
- factorial *= n;
- n--;
- } while (n > 0);
- }
- Console.WriteLine("n! = " + factorial);
- */
- /*
- ConsoleKeyInfo cki;
- cki = Console.ReadKey();
- Console.WriteLine(cki.Key == ConsoleKey.RightArrow);
- int positionX = 0;
- int positionY = 0;
- do {
- while (!Console.KeyAvailable)
- {
- // Console.WriteLine("Cycle trough your live");
- Console.Clear();
- Console.SetCursorPosition(positionX, positionY);
- Console.Write("*");
- System.Threading.Thread.Sleep(100);
- }
- cki = Console.ReadKey(true);
- switch (cki.Key)
- {
- case ConsoleKey.RightArrow:
- positionX++;
- break;
- case ConsoleKey.LeftArrow:
- positionX--;
- break;
- case ConsoleKey.DownArrow:
- positionY++;
- break;
- case ConsoleKey.UpArrow:
- positionY--;
- break;
- }
- } while (cki.Key != ConsoleKey.Escape);
- */
- /*
- int n = 0;
- do
- {
- Console.Write("Please enter a positive number: ");
- n = int.Parse(Console.ReadLine());
- } while(n < 0);
- */
- /*
- int n = int.Parse(Console.ReadLine());
- int m = int.Parse(Console.ReadLine());
- int number = n;
- decimal product = 1;
- do
- {
- product *= number;
- number++;
- }
- while (number <= m);
- Console.WriteLine("product[{0}..{1}] = {2}", n, m, product);
- */
- /*
- int i = 0;
- while (i < 10)
- {
- Console.WriteLine(i);
- i++;
- }
- */
- /*
- for (int i = 0; i < 10; i++)
- {
- Console.WriteLine(i);
- }
- */
- /*
- int sum = 0;
- for (int i = 0; i <= 5; i++)
- {
- sum += i;
- }
- Console.WriteLine(sum);
- */
- /*
- int factorial = 1;
- for (int i = 1; i <= 5; i++)
- {
- factorial *= i;
- }
- Console.WriteLine(factorial);
- */
- /*
- Random rand = new Random();
- int n = rand.Next(1, 10);
- for (;;)
- {
- Console.WriteLine("cycle");
- }
- */
- /*
- for (int i = 1, sum = 1; i <= 128; i = i * 2, sum += i)
- {
- Console.WriteLine("i={0}, sum={1}", i, sum);
- }
- */
- /*
- int n = int.Parse(Console.ReadLine());
- int m = int.Parse(Console.ReadLine());
- decimal result = 1;
- for (int i = 0; i < m; i++)
- {
- result *= n;
- }
- Console.WriteLine("n^m = " + result);
- */
- /*
- int n = int.Parse(Console.ReadLine());
- int sum = 0;
- for (int i = 1; i <= n; i += 2)
- {
- if (i % 7 == 0)
- {
- continue;
- }
- sum += i;
- }
- Console.WriteLine("sum = {0}", sum);
- */
- /*
- string[] group = { "Stoyan", "Vasko", "Petko", "Ivan" };
- // foreach (string name in group)
- foreach (var name in group)
- {
- Console.WriteLine(name);
- }
- */
- /*
- string[] days = {
- "Monday", "Tuesday", "Wednesday", "Thursday",
- "Friday", "Saturday", "Sunday" };
- foreach (var day in days)
- {
- Console.WriteLine(day);
- }
- */
- /*
- int n = int.Parse(Console.ReadLine());
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < i; j++)
- {
- Console.Write(j);
- }
- Console.WriteLine();
- }
- */
- /*
- int n = int.Parse(Console.ReadLine());
- int m = int.Parse(Console.ReadLine());
- for (int number = n; number <= m; number++)
- {
- bool prime = true;
- int divider = 2;
- int maxDivider = (int)Math.Sqrt(number);
- while (divider <= maxDivider)
- {
- if (number % divider == 0)
- {
- prime = false;
- break;
- }
- divider++;
- }
- if (prime)
- Console.Write("{0} ", number);
- }
- */
- /*
- int sum = 0;
- int i = 0;
- while(i < 100)
- {
- Console.WriteLine(i);
- if (i % 2 == 0)
- {
- i++;
- continue;
- }
- sum += i;
- i++;
- }
- */
- /*
- breakIn:;
- int outerCounter = 0;
- for (int outer = 0; outer < 10; outer++)
- {
- for (int inner = 0; inner < 10; inner++)
- {
- if (inner % 3 == 0)
- continue; if (outer == 7)
- break; if (inner + outer > 9)
- goto breakOut;
- }
- outerCounter++;
- }
- breakOut:
- goto breakIn;
- */
- /*
- for (int a = 1; a <= 9; a++)
- for (int b = 0; b <= 9; b++)
- for (int c = 0; c <= 9; c++)
- for (int d = 0; d <= 9; d++)
- if (a + b == c + d)
- Console.WriteLine("{0}{1}{2}{3}", a, b, c, d);
- */
- /*
- int counter = 0;
- int i1, i2, i3, i4, i5, i6;
- for (i1 = 1; i1 <= 44; i1++)
- for (i2 = i1 + 1; i2 <= 45; i2++)
- for (i3 = i2 + 1; i3 <= 46; i3++)
- for (i4 = i3 + 1; i4 <= 47; i4++)
- for (i5 = i4 + 1; i5 <= 48; i5++)
- for (i6 = i5 + 1; i6 <= 49; i6++)
- {
- // Console.WriteLine("{0} {1} {2} {3} {4} {5}", i1, i2, i3, i4, i5, i6);
- // Try to comment the above row to speed up the program
- counter++;
- }
- Console.WriteLine("{0} combinations", counter);
- */
- // Console.ForegroundColor
- }
- static int factorial(int n)
- {
- int factorial = 1;
- while (n > 0)
- {
- checked
- {
- factorial *= n--;
- }
- }
- return factorial;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment