Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ARM
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here string start; Console.WriteLine("ARM Software Developer Test Questions"); Console.WriteLine("Created by -- Eyiwunmi Dawodu 07011860291"); Console.WriteLine("Question 1 and 3 were answered"); do { Console.WriteLine("Enter 1 to run question 1 and 3 to enter question 3"); string userInput; int select = 0; bool isNum; do { userInput = Console.ReadLine(); isNum = int.TryParse(userInput, out select); } while (isNum == false); if (select == 1) { Console.WriteLine("Given an array and a number k where k is smaller than size of array, "); Console.WriteLine("find the k’th smallest element in the given array. It is given that all array elements are distinct."); Console.WriteLine("Array = { 7, 10, 4, 3, 20, 15 }"); Console.WriteLine("Smallest Number"); int[] arr = { 7, 10, 4, 3, 20, 15 }; int k = 3; int result = Question1(arr, k); Console.WriteLine(result); } else if (select == 3) { Console.WriteLine("Given a set of non-negative integers, and a value sum, determine if there is a subset "); Console.WriteLine("of the given set with sum equal to given sum."); Console.WriteLine("Array = { 3, 34, 4, 12, 5, 2 }"); int[] set = { 3, 34, 4, 12, 5, 2 }; var result = Question3(set); Console.WriteLine(result.Firstnum + " -- " + result.Secondnum); } else { Console.WriteLine(select + " is not a valid option."); } Console.WriteLine("Next question? Yes / No"); Console.WriteLine("\n"); start = Console.ReadLine(); } while (start.ToLower() == "yes"); } public static int Question1(int[] inputArrays, int k) { Array.Sort(inputArrays); var smallval = inputArrays[k - 1]; return smallval; } public static Res Question3(int[] inputArrays) { Array.Sort(inputArrays); Res result = new Res(); int arrLenght = inputArrays.Length; for (int a = 0; a < arrLenght; a++) { for (int b = 1; b < arrLenght; b++) { if (inputArrays[a] + inputArrays[b] == 9) { result.Firstnum = inputArrays[a]; result.Secondnum = inputArrays[b]; return result; } } } return result; } public class Res { public int Firstnum { get; set; } public int Secondnum { get; set; } } } }
run
|
edit
|
history
|
help
0
Product, Category, Composition and Inheritance
Ref
30272 Program Ex6_1 else_if
schach 1 sem
Обненник 24/7
Speed test for email text replacements
Xml in C#
min tree
Ejemplos polimorfismos con interfaces y posibles usos sencillos c#
Prime number