Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Numerics;
- namespace DataTypeVariables
- {
- class Program
- {
- static void Main(string[] args)
- {
- }
- private static void Compare_FloatingNumbers()
- {
- var diff = 0.0;
- var a = double.Parse(Console.ReadLine());
- var b = double.Parse(Console.ReadLine());
- //
- const double eps = 0.000001;
- diff = a - b;
- diff = Math.Abs(diff);
- if (diff < eps)
- {
- Console.WriteLine("True");
- }
- else
- {
- Console.WriteLine("False");
- }
- //Console.WriteLine(diff);
- }
- private static void DifferentInteger_Size()
- {
- //Console.WriteLine(long.MaxValue); ///9223372036854775807
- //Console.WriteLine(value: sbyte.MinValue); //
- var integer = BigInteger.Parse(Console.ReadLine());
- //
- List<string> printData = new List<string>();
- var sbytee = integer >= sbyte.MinValue && integer <= sbyte.MaxValue;
- var bytee = integer >= byte.MinValue && integer <= byte.MaxValue;
- var shortt = integer >= short.MinValue && integer <= short.MaxValue;
- var ushortt = integer >= ushort.MinValue && integer <= ushort.MaxValue;
- var intt = integer >= int.MinValue && integer <= int.MaxValue;
- var uintt = integer >= uint.MinValue && integer <= uint.MaxValue;
- var longg = integer >= long.MinValue && integer <= long.MaxValue;
- var ulongg = integer >= ulong.MinValue && integer <= ulong.MaxValue;
- //
- if (sbytee)
- {
- var temp = "* sbyte";
- printData.Add(temp);
- }
- if (bytee)
- {
- var temp = "* byte";
- printData.Add(temp);
- }
- if (shortt)
- {
- var temp = "* short";
- printData.Add(temp);
- }
- if (ushortt)
- {
- var temp = "* ushort";
- printData.Add(temp);
- }
- if (intt)
- {
- var temp = "* int";
- printData.Add(temp);
- }
- if (uintt)
- {
- var temp = "* uint";
- printData.Add(temp);
- }
- if (longg)
- {
- var temp = "* long";
- printData.Add(temp);
- }
- if (sbytee || bytee || shortt || ushortt || intt || uintt || longg)
- {
- Console.WriteLine($"{integer} can fit in:");
- foreach (var data in printData)
- {
- Console.WriteLine(data);
- }
- }
- else
- {
- Console.WriteLine($"{integer} can't fit in any type");
- }
- }
- private static void ThePhotographer()
- {
- //Thea => the Photographer :)
- var numPictures = int.Parse(Console.ReadLine());
- var filterTime = int.Parse(Console.ReadLine());
- var percentOfGoodPic = Math.Ceiling(double.Parse(Console.ReadLine()));
- var uploadTime = int.Parse(Console.ReadLine());
- //
- var sortetPic = (numPictures * (percentOfGoodPic)) / 100.0;
- //
- long timeFilter = numPictures * filterTime;
- long timeUpload = (long)(Math.Ceiling(sortetPic) * uploadTime);
- long allTime = timeUpload + timeFilter;
- //
- TimeSpan t = TimeSpan.FromSeconds(allTime);
- string printTime = string.Format($"{t.Days}:{t.Hours:d2}:{t.Minutes:d2}:{t.Seconds:d2}");
- Console.WriteLine(printTime);
- }
- private static void Print_Character()
- {
- int start = int.Parse(Console.ReadLine());
- int end = int.Parse(Console.ReadLine());
- //
- string temp = "";
- //
- List<int> num = new List<int>();
- for (int i = start; i <= end; i++)
- {
- num.Add(i);
- }
- foreach (char item in num)
- {
- temp += item + " ";
- }
- Console.WriteLine(temp);
- }
- private static void Refacktor_PrimeNumber()
- {
- int num = int.Parse(Console.ReadLine());
- for (int i = 2; i <= num; i++)
- {
- bool checkForPrime = true;
- for (int j = 2; j <= Math.Sqrt(i); j++)
- {
- if (i % j == 0)
- {
- checkForPrime = false;
- break;
- }
- }
- Console.WriteLine($"{i} -> {checkForPrime}");
- }
- }
- private static void Hexadecima_Binary()
- {
- var num = int.Parse(Console.ReadLine());
- var hexadecimal = (Convert.ToString(num, 16).ToUpper());
- string binary = Convert.ToString(num, 2);
- Console.WriteLine(hexadecimal);
- Console.WriteLine((binary));
- }
- private static void Vowel_Digit()
- {
- var input = Console.ReadLine();
- var print = "";
- if (input == "a" || input == "A" || input == "O" || input == "o" || input == "I" || input == "i" || input == "e" || input == "E"
- || input == "U" || input == "u")
- {
- print = "vowel";
- }
- else if (input == "0" || input == "1" || input == "2" || input == "3" || input == "4" || input == "5" || input == "6" || input == "7" || input == "8" ||
- input == "9")
- {
- print = "digit";
- }
- else
- {
- print = "other";
- }
- Console.WriteLine(print);
- }
- private static void Rectangle_Properties()
- {
- double a = double.Parse(Console.ReadLine());
- double b = double.Parse(Console.ReadLine());
- //
- var perimeter = (a * 2) + (b * 2);
- var area = a * b;
- var diagonal = a * a + b * b;
- Console.WriteLine(perimeter);
- Console.WriteLine(area);
- Console.WriteLine(Math.Sqrt(diagonal));
- }
- private static void Convert_Metrics()
- {
- int distanceMeters = int.Parse(Console.ReadLine());
- var hours = decimal.Parse(Console.ReadLine());
- var minutes = decimal.Parse(Console.ReadLine());
- var seconds = decimal.Parse(Console.ReadLine());
- //
- var metersPerSeconds = ((hours * 60) + minutes) * 60;
- float meterPerSec = (float)distanceMeters / (float)metersPerSeconds;
- //
- var metersToKm = distanceMeters / 1000;
- var time = (((seconds / 60) + minutes) / 60) + hours;
- float kmPerHours = (float)metersToKm / (float)time;
- //
- //Assume 1 mile = 1609 meters.
- var metersToMile = distanceMeters / 1609.0;
- var timeMile = (((seconds / 60) + minutes) / 60) + hours;
- float milePerHour = (float)metersToMile / (float)timeMile;
- Console.WriteLine($"{Math.Round(meterPerSec, 7)}");
- Console.WriteLine($"{Math.Round(kmPerHours, 7)}");
- Console.WriteLine($"{Math.Round(milePerHour, 7)}");
- }
- private static void CenturiesToNanoseconds()
- {
- byte centuries = byte.Parse(Console.ReadLine());
- int years = centuries * 100;
- int days = (int)((double)years * 365.2422);
- long hours = days * 24;
- long minutes = hours * 60;
- long secundes = minutes * 60;
- long millieseconds = secundes * 1000;
- decimal microseconds = millieseconds * 1000;
- decimal nanoseconds = microseconds * 1000;
- Console.WriteLine($"{centuries} centuries = {years} years = {days} days = {hours} hours = {minutes}" +
- $" minutes = {secundes} seconds = {millieseconds}" +
- $" milliseconds = {microseconds} microseconds = {nanoseconds} nanoseconds");
- }
- private static void ReverseString()
- {
- string letter1 = Console.ReadLine();
- string letter2 = Console.ReadLine();
- string letter3 = Console.ReadLine();
- string str = (letter1 + letter2 + letter3);
- string revers = "";
- for (int i = str.Length - 1; i >= 0; i--)
- {
- revers += str[i];
- }
- Console.WriteLine(revers);
- }
- private static void EmployeeData()
- {
- string firstName = Console.ReadLine();
- string secondName = Console.ReadLine();
- byte age = byte.Parse(Console.ReadLine());
- char sex = char.Parse(Console.ReadLine());
- long personalIdNumber = long.Parse(Console.ReadLine());
- int UEN = int.Parse(Console.ReadLine());
- //
- Console.WriteLine($"First name: {firstName}");
- Console.WriteLine($"Last name: {secondName}");
- Console.WriteLine($"Age: {age}");
- Console.WriteLine($"Gender: {sex}");
- Console.WriteLine($"Personal ID: {personalIdNumber}");
- Console.WriteLine($"Unique Employee number: {UEN}");
- }
- private static void Exchange_Variables_Value()
- {
- var a = 5;
- var b = 10;
- var c = 0;
- Console.WriteLine("Before:");
- Console.WriteLine($"a = {a}");
- Console.WriteLine($"b = {b}");
- Console.WriteLine("After:");
- c = a;
- a = b;
- b = c;
- Console.WriteLine($"a = {a}");
- Console.WriteLine($"b = {b}");
- }
- private static void String_Object()
- {
- string hello = "Hello";
- string world = "World";
- object obj = hello + " " + world;
- string str = (string)obj;
- Console.WriteLine(str);
- }
- private static void Bool_Variable()
- {
- string input = Console.ReadLine();
- var isTrue = Convert.ToBoolean(input);
- if (isTrue)
- {
- Console.WriteLine("Yes");
- }
- else
- {
- Console.WriteLine("No");
- }
- }
- private static void Hexadecimal()
- {
- string data = Console.ReadLine();
- var n = Convert.ToInt32(data, 16);
- Console.WriteLine(n.ToString());
- }
- private static void String_Char()
- {
- string f = "Software University";
- char b = 'B';
- char y = 'y';
- char e = 'e';
- string s = "I love programming";
- Console.WriteLine(f);
- Console.WriteLine(b);
- Console.WriteLine(y);
- Console.WriteLine(e);
- Console.WriteLine(s);
- }
- private static void Floating_Numbers()
- {
- decimal n1 = 3.141592653589793238m;
- double n2 = 1.60217657;
- decimal n3 = 7.8184261974584555216535342341M;
- Console.WriteLine(n1);
- Console.WriteLine(n2);
- Console.WriteLine(n3);
- }
- private static void Integers()
- {
- sbyte num1 = -100;
- byte num2 = 128;
- short num3 = -3540;
- ushort num4 = 64876;
- uint num5 = 2147483648;
- int num6 = -1141583228;
- long num7 = -1223372036854775808;
- //
- Console.WriteLine(num1);
- Console.WriteLine(num2);
- Console.WriteLine(num3);
- Console.WriteLine(num4);
- Console.WriteLine(num5);
- Console.WriteLine(num6);
- Console.WriteLine(num7);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement