Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class Program
- {
- public static void Main()
- {
- //зад. 1
- //2025
- static void Main(string[] args)
- {
- int x = 2042;
- ConvertBinary(x);
- ConvertOctal(x);
- Console.WriteLine();
- Console.WriteLine("Hexadecimal: " + ConvertHexadecimal(x));
- }
- private static void ConvertBinary(int decimalNumber)
- {
- int remainder;
- string result = string.Empty;
- while (decimalNumber > 0)
- {
- remainder = decimalNumber % 2;
- decimalNumber /= 2;
- result = remainder.ToString() + result;
- }
- Console.WriteLine("Binary: {0}", result);
- }
- private static void ConvertOctal(int decValue)
- {
- int counter, i = 1, j;
- int[] octalValue = new int[80];
- counter = decValue;
- while (counter != 0)
- {
- octalValue[i++] = counter % 8;
- counter /= 8;
- }
- Console.Write("Octal Number: ");
- for (j = i - 1; j > 0; j--)
- Console.Write(octalValue[j]);
- }
- private static string ConvertHexadecimal(int n)
- {
- if (n < 1) return "0";
- int hex = n;
- string hexStr = string.Empty;
- while (n > 0)
- {
- hex = n % 16;
- if (hex < 10)
- hexStr = hexStr.Insert(0, Convert.ToChar(hex + 48).ToString());
- else
- hexStr = hexStr.Insert(0, Convert.ToChar(hex + 55).ToString());
- n /= 16;
- }
- return hexStr;
- }
- //зад. 2
- //Тест 1 - 2 II)
- Console.Write("Enter B: ");
- int B = int.Parse(Console.ReadLine());
- Console.Write("Enter y:");
- int y = int.Parse(Console.ReadLine());
- Console.WriteLine((B + Math.Pow(Math.Sin(Math.Pow(Math.PI, 4)), 2)) / (Math.Pow(Math.Cos(6), ((double)1 / 5)) + Math.Abs((double)1 / Math.Tan(y))));
- //зад. 3
- //63
- Console.Write("Enter k: ");
- int k = int.Parse(Console.ReadLine());
- double y = -1;
- if (k == 1)
- {
- y = 6.7;
- }
- else if (k == 2)
- {
- y = 6.7 + 9 * k;
- }
- else if (k == 3)
- {
- y = 6.7 + 9 * k + 7 * Math.Pow(k, 2);
- }
- Console.WriteLine($"y = {y}");
- //зад. 4
- //213ж
- Console.WriteLine(TangensCalc(1));
- double TangensCalc(int v)
- {
- if (v == 100)
- {
- return Math.Tan(v);
- }
- return Math.Tan(v + TangensCalc(v + 1));
- }
- //зад. 5
- //379
- Random random = new Random();
- int[] arr = new int[132];
- for (int i = 0; i < arr.Length; i++)
- {
- arr[i] = (random.Next(0, 150));
- }
- for (int i = 0; i < arr.Length; i++)
- {
- if (arr[i] % 2 != 0)
- {
- Console.WriteLine(arr[i]);
- }
- }
- Console.Write("Enter 5 numbers: ");
- int[] numbers = new int[5];
- string[] input = Console.ReadLine().Split(' ');
- for (int i = 0; i < numbers.Length; i++)
- numbers[i] = int.Parse(input[i]);
- int proizvedenie = numbers[0] * numbers[1] * numbers[2] * numbers[3] * numbers[4];
- Console.WriteLine(proizvedenie);
- double koren = (Math.Pow(proizvedenie, ((double)1 / 5)));
- Console.WriteLine(koren);
- Console.Write("Enter a= ");
- int a = int.Parse(Console.ReadLine());
- Console.Write("Enter b= ");
- int b = int.Parse(Console.ReadLine());
- Console.Write("Enter c= ");
- int c = int.Parse(Console.ReadLine());
- Console.WriteLine("Output is " + Sss(Math.Abs(c - b)) * Sss(a + c));
- BigInteger Sss(int k)
- {
- BigInteger product = 1;
- bool flag = true;
- Random r = new Random();
- for (int i = 0; i < k; i++)
- {
- int a = r.Next(0, 100);
- if ((a <= 99 && a >= 10) && a % 10 == 5)
- {
- flag = false;
- product *= a;
- }
- }
- if (flag)
- return 0;
- else
- return product;
- }
- //зад. 6
- //398
- Console.Write("Days in a month[1, 31]: ");
- int n = int.Parse(Console.ReadLine());
- while (n <= 0 && n > 31)
- {
- Console.WriteLine("Invalid days! Try again[1, 31]: ");
- n = int.Parse(Console.ReadLine());
- }
- Console.WriteLine("Station A");
- var stationA = Rains(n);
- Console.WriteLine("Station B");
- var stationB = Rains(n);
- Console.WriteLine("Station C");
- var stationC = Rains(n);
- double arithmeticA = Arithmetic(stationA);
- double arithmeticB = Arithmetic(stationB);
- double arithmeticC = Arithmetic(stationC);
- int overArithmeticA = 0, overArithmeticB = 0, overArithmeticC = 0;
- for (int i = 0; i < n; i++)
- {
- if (stationA[i] > arithmeticA)
- overArithmeticA++;
- if (stationB[i] > arithmeticB)
- overArithmeticB++;
- if (stationC[i] > arithmeticC)
- overArithmeticC++;
- }
- Console.WriteLine($"The Arithmetic of Station A is: {arithmeticA}! And has {overArithmeticA} days exceeding the arithmetic!");
- Console.WriteLine($"The Arithmetic of Station B is: {arithmeticB}! And has {overArithmeticB} days exceeding the arithmetic!");
- Console.WriteLine($"The Arithmetic of Station C is: {arithmeticC}! And has {overArithmeticC} days exceeding the arithmetic!");
- double Arithmetic(double[] days)
- {
- double sum = 0;
- int n = days.Length;
- for (int i = 0; i < n; i++)
- sum += days[i];
- return sum / n;
- }
- double[] Rains(int days)
- {
- double[] rains = new double[days];
- double n;
- for (int i = 0; i < days; i++)
- {
- Console.Write($"Day {i + 1}: ");
- n = double.Parse(Console.ReadLine());
- if (n >= 0)
- rains[i] = n;
- else
- i--;
- }
- Console.WriteLine();
- return rains;
- }
- //зад. 7
- //372аб
- static void Main(string[] args)
- {
- Console.Write("Въведете дължина на масива: ");
- int n = int.Parse(Console.ReadLine());
- while (n < 1 || n > 50)
- {
- Console.WriteLine("Дължината трябва да е между 1 и 50!");
- n = int.Parse(Console.ReadLine());
- }
- string[] cities = new string[n];
- InputElements(cities);
- Console.WriteLine("Градове съдържащи 'град' или 'Град' в името");
- StringContain(cities);
- }
- private static void StringContain(string[] cities)
- {
- string s1 = "град";
- string s2 = "Град";
- foreach (var item in cities)
- {
- if (item.Contains(s1) || item.Contains(s2))
- {
- Console.WriteLine(item);
- }
- }
- }
- private static void InputElements(string[] cities)
- {
- for (int i = 0; i < cities.Length; i++)
- {
- Console.Write("Въведи град: ");
- string city = Console.ReadLine();
- cities[i] = FirstLetterToUpper(city);
- }
- }
- public static string FirstLetterToUpper(string str)
- {
- if (str == null)
- return null;
- else
- return char.ToUpper(str[0]) + str.Substring(1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment