Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Problem 1. Bigger Number ////////////////////////////////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace BiggerNumber_1
- {
- class BiggerNumber_1
- {
- static int GetMax(int a, int b)
- {
- int c = Math.Max(a, b);
- return c;
- }
- static void Main(string[] args)
- {
- int first = int.Parse(Console.ReadLine());
- int second = int.Parse(Console.ReadLine());
- int max = GetMax(first, second);
- Console.WriteLine(max);
- }
- }
- }
- Problem 2. Last Digit of Number //////////////////////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace LastDigit_2
- {
- class LastDigit_2
- {
- static string[] number = { "zero", "one", "two", "three", "four", "five",
- "six", "seven", "eight", "nine"};
- static void PrintNumber(int num)
- {
- int lastDigit = num % 10;
- Console.WriteLine(number[lastDigit]);
- }
- static void Main(string[] args)
- {
- int a = int.Parse(Console.ReadLine());
- PrintNumber(a);
- }
- }
- }
- Problem 3. Larger Than Neighbours /////////////////////////////////////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace LargerNeighbours_3
- {
- class LargerNeighbours_3
- {
- static int[] arr;
- static bool CheckIfGreater(int idx)
- {
- bool isGreater;
- if (idx == 0)
- {
- isGreater = arr[idx] > arr[idx + 1];
- }
- else if (idx == arr.Length - 1)
- {
- isGreater = arr[idx] > arr[idx - 1];
- }
- else
- {
- isGreater = arr[idx] > arr[idx - 1] && arr[idx] > arr[idx + 1];
- }
- return isGreater;
- }
- static void Main(string[] args)
- {
- string inputArray = Console.ReadLine();
- arr = inputArray.Split().Select(int.Parse).ToArray();
- for (int i = 0; i < arr.Length; i++)
- {
- Console.WriteLine(CheckIfGreater(i));
- }
- }
- }
- }
- Problem 4. First Larger Than Neighbours //////////////////////////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FirstLarger_4
- {
- class FirstLarger_4
- {
- static int[] arr;
- static bool GetFirstLarger(int idx)
- {
- bool firstLarger;
- if (idx == 0)
- {
- firstLarger = arr[idx] > arr[idx + 1];
- }
- else if (idx == arr.Length - 1)
- {
- firstLarger = arr[idx] > arr[idx - 1];
- }
- else
- {
- firstLarger = arr[idx] > arr[idx - 1] && arr[idx] > arr[idx + 1];
- }
- return firstLarger;
- }
- static void Main(string[] args)
- {
- string inputArray = Console.ReadLine();
- arr = inputArray.Split().Select(int.Parse).ToArray();
- bool isGreater = false;
- for (int i = 0; i < arr.Length; i++)
- {
- if (GetFirstLarger(i))
- {
- Console.WriteLine("First Larger element is {0}", i);
- isGreater = true;
- break;
- }
- }
- if (!isGreater)
- {
- Console.WriteLine("-1");
- }
- }
- }
- }
- Problem 5. Reverse Number ///////////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ReverseNum_5
- {
- class ReverseNum_5
- {
- static double ReverseNumber(double num)
- {
- string number = num.ToString();
- char[] reverse = number.ToCharArray();
- Array.Reverse(reverse);
- string revNum = new string(reverse);
- double newNum = double.Parse(revNum);
- return newNum;
- }
- static void Main(string[] args)
- {
- double number = double.Parse(Console.ReadLine());
- Console.WriteLine(ReverseNumber(number));
- }
- }
- }
- Problem 6. Number Calculations ///////////////////////////////////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _06.NumberCalculations
- {
- class NumberCalculations
- {
- static void Main(string[] args)
- {
- decimal[] decimals = Console.ReadLine().Split(' ').Select(decimal.Parse).ToArray();
- double[] doubles = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
- Console.WriteLine(FindMinValue(decimals));
- Console.WriteLine(FindMinValue(doubles));
- Console.WriteLine(FindMaxValue(decimals));
- Console.WriteLine(FindMaxValue(doubles));
- Console.WriteLine(FindAvgValue(decimals));
- Console.WriteLine(FindAvgValue(doubles));
- Console.WriteLine(FindSum(decimals));
- Console.WriteLine(FindSum(doubles));
- Console.WriteLine(FindProduct(decimals));
- Console.WriteLine(FindProduct(doubles));
- }
- static decimal FindMinValue(decimal[] numbers)
- {
- decimal result = Decimal.MaxValue;
- foreach (decimal n in numbers)
- {
- result = (n < result) ? n : result;
- }
- return result;
- }
- static double FindMinValue(double[] numbers)
- {
- double result = Double.MaxValue;
- foreach (double n in numbers)
- {
- result = (n < result) ? n : result;
- }
- return result;
- }
- static decimal FindMaxValue(decimal[] numbers)
- {
- decimal result = Decimal.MinValue;
- foreach (decimal n in numbers)
- {
- result = (n > result) ? n : result;
- }
- return result;
- }
- static double FindMaxValue(double[] numbers)
- {
- double result = Double.MinValue;
- foreach (double n in numbers)
- {
- result = (n > result) ? n : result;
- }
- return result;
- }
- static decimal FindAvgValue(decimal[] numbers)
- {
- decimal result = 0;
- foreach (decimal n in numbers)
- {
- result += n;
- }
- result /= numbers.Length;
- return result;
- }
- static double FindAvgValue(double[] numbers)
- {
- double result = 0;
- foreach (double n in numbers)
- {
- result += n;
- }
- result /= numbers.Length;
- return result;
- }
- static decimal FindSum(decimal[] numbers)
- {
- decimal result = 0;
- foreach (decimal n in numbers)
- {
- result += n;
- }
- return result;
- }
- static double FindSum(double[] numbers)
- {
- double result = 0;
- foreach (double n in numbers)
- {
- result += n;
- }
- return result;
- }
- static decimal FindProduct(decimal[] numbers)
- {
- decimal result = 1;
- foreach (decimal n in numbers)
- {
- result *= n;
- }
- return result;
- }
- static double FindProduct(double[] numbers)
- {
- double result = 1;
- foreach (double n in numbers)
- {
- result *= n;
- }
- return result;
- }
- }
- }
- Problem 7. * Generic Array Sort ///////////////////////////////////////////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace GenericArraySort_7
- {
- class GenericArraySort_7
- {
- static void SortArray<T>(List<T> list) where T : IComparable
- {
- for (int a = 0; a < list.Count - 1; a++)
- {
- int minValue = a;
- for (int b = a + 1; b < list.Count; b++)
- {
- if (list[minValue].CompareTo(list[b]) > 0)
- {
- minValue = b;
- }
- }
- T temp = list[a];
- list[a] = list[minValue];
- list[minValue] = temp;
- }
- foreach (var l in list)
- {
- Console.Write(l + " ");
- }
- }
- static void Main(string[] args)
- {
- List<int> number = new List<int> { 3, 2, 16, 24, 5, 1, 27, 80, 9 };
- List<string> words = new List<string> { "am", "em", "omo", "zaz", "cba", "baa" };
- List<DateTime> dates = new List<DateTime> { new DateTime(2012, 02, 01),
- new DateTime(2015, 05, 06), new DateTime(1875, 03, 03) };
- SortArray(number);
- Console.WriteLine();
- SortArray(words);
- Console.WriteLine();
- SortArray(dates);
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement