Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- static void Count()
- {
- Console.WriteLine("Введите строку для подсчета в ней слов и букв");
- int ch = 0, wd = 1;
- string st = Console.ReadLine();
- while (st != "")
- {
- if (st[0] == ' ')
- {
- wd++;
- }
- else
- {
- ch++;
- }
- st = st.Remove(0,1);
- }
- Console.WriteLine("Букв: {0}\nСлов: {1}",ch, wd);
- }
- static int fact(int i)
- {
- if (i > 1)
- return i * fact(i - 1);
- else
- return 1;
- }
- static int fib(int i)
- {
- if (i > 2)
- return fib(i - 1) + fib(i - 2);
- else
- return 1;
- }
- static void game (int x, int y)
- {
- Console.WriteLine("\nВаши координаты (x,y) - ({0} ; {1})", x, y);
- Console.WriteLine("Используйте клавиши W A S D для перемещения, 0 для выхода");
- char dir = ' ';
- Console.Write("({0};{1}) - ", x, y);
- while (dir != '0')
- {
- dir = (char)Console.Read();
- switch (dir)
- {
- default: Console.WriteLine("Попробуйте еще раз..."); Console.Write("({0};{1}) - ", x, y); continue;
- case'\r': ; continue;
- case'\n': ; continue;
- case 'w': y++; Console.Write("({0};{1}) - ", x, y); continue;
- case 'a': x--; Console.Write("({0};{1}) - ", x, y); continue;
- case 's': y--; Console.Write("({0};{1}) - ", x, y); continue;
- case 'd': x++; Console.Write("({0};{1}) - ", x, y); continue;
- case '0': ; continue;
- //Console.WriteLine("Попробуйте еще раз..."); break;
- }
- break;
- }
- Console.WriteLine("Вы закончили игру в координатах ({0};{1})", x, y);
- }
- static bool IsSimple(int x)
- {
- for (int i = 2; i < Math.Sqrt(x); i++)
- {
- if (x % i == 0)
- {
- return false;
- }
- }
- return true;
- }
- static void Simple(int x)
- {
- Console.WriteLine("\nРаспределение простых чисел до {0}:", x);
- for (int i = 1; i <= x; i++)
- {
- if (IsSimple(i))
- {
- Console.Write('@');
- }
- else
- {
- Console.Write('?');
- }
- }
- Console.WriteLine();
- }
- static void Main()
- {
- //счетчик букв
- Count();
- Console.WriteLine();
- //факториал от 5
- int f1 = fact(5);
- Console.WriteLine("Факториал пяти - {0}",f1);
- Console.WriteLine();
- //пятый член фиббоначи
- int f2 = fib(5);
- Console.WriteLine("Пятый член фиббоначи - {0}",f2);
- // странная игра в координатах
- game(10, 10);
- // простые числа
- Simple(50);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment