using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main(string[] args)
Console.WriteLine("Please uncomment a test");
Calculate( 16,21);
}
public static void Calculate(int n, int p)
double x=0;
x= n /(p/100);
Console.WriteLine("{0} is {1}% of {2}",n,p,x);
Console.ReadLine();
//*********************
//*** Question 1
//*** Describe the output of this program
/*
int[] arr = new int[] {1 ,2 ,3 ,4 ,5 };
fun1(ref arr);
static void fun1(ref int[] array)
for (int i = 0; i < array.Length; i=i+2)
array[i] = array[i] + 10;
Console.WriteLine(string.Join(",", array));
*/
//*** Question 2
int num = 5;
int square = 0, cube = 0;
Mul (num, ref square, ref cube);
Console.WriteLine(square + " & " +cube);
static void Mul (int num, ref int square, ref int cube)
square = num * num;
cube = num * num * num;
//*** Question 3
//*** Write a function that calculates a circle's circumference (Pi*radius*2)
public static void Main()
Console.WriteLine("Enter the circle's radius");
int radius = Convert.ToInt32(Console.ReadLine());
double res = CalcCircumference(radius);
Console.WriteLine("Circumference is: " + res);
static double CalcCircumference(int r) {
//applicant's code goes here
return 2 * Math.PI * r;
//*** Question 4
//*** Write a program to check two given integers, and return true if one of them is 30 or if their sum is 30.
Console.WriteLine(test(30, 0));
Console.WriteLine(test(25, 5));
Console.WriteLine(test(20, 30));
Console.WriteLine(test(20, 25));
public static bool test(int x, int y)
return x == 30 || y == 30 || (x + y == 30);
//*** Question 5
//*** Write a function to exchange the first and last characters in a given string and return the new string.
Console.WriteLine(test("abc"));
Console.WriteLine(test("abcdef"));
Console.WriteLine(test("xy"));
Console.WriteLine(test("x"));
public static string test(string str)
return str.Length > 1
? str.Substring(str.Length - 1) + str.Substring(1, str.Length - 2) + str.Substring(0, 1) : str;
//*** Question 6
//*** Write a program to print all unique elements in an array.
int[] arr1 = new int[]{1, 1, 4, 3, 5, 3, 4, 6, 9, 9};
var res = FindUniqueValues(arr1);
Console.Write("\nThe unique elements found in the array are : \n");
Console.Write(String.Join(",", res));
public static List<int> FindUniqueValues(int[] arr){
List<int> res = new List<int>();
int n = 10;
int ctr = 0;
int i, j, k;
for(i=0; i<n; i++)
ctr=0;
//Check duplicate before the current position and increase counter by 1 if found.
for(j=0; j<i; j++)
//Increment the counter when the search value is duplicate.
if(arr[i]==arr[j])
ctr++;
//Check duplicate after the current position and increase counter by 1 if found.
for(k=i+1; k<n; k++)
if(arr[i]==arr[k])
//Print the value of the current position of the array as unique value when counter remain contains its initial value.
if(ctr==0)
res.Add(arr[i]);
return res;
//*** Question 7 (LINQ)
//*** Write a function that finds and adds all the even numbers in the array
public static void Main(int[] intArray) {
long res = TotalAllEvenNumbers(arr);
Console.WriteLine(res);
static long TotalAllEvenNumbers(int[] intArray) {
return intArray.Where(i => i % 2 == 0).Sum(i => (long)i);
//*** Question 8 (LINQ)
//*** Find which numbers in the array when squared are more than 20
var arr1 = new[] { 3, 9, 2, 8, 6, 5 };
var res = FindAllNumbers(arr1);
Console.WriteLine(String.Join(",", res));
static List<int> FindAllNumbers(int[] intArray) {
IEnumerable<int> sqNo = intArray.Where(x => (x*x)>20);
return sqNo.ToList();
//*** Question 9 (LINQ)
//*** Write a program to display the characters and frequency of character from giving string.
public class ResultObject{
public Char Character {get; set;}
public int Frequency {get; set;}
string str = "arkusnexus";
var res = FindAllFreq(str);
Console.Write("The frequency of the characters are :\n");
foreach(ResultObject item in res)
Console.WriteLine("Character "+item.Character + ": " + item.Frequency+" times");
public static List<ResultObject> FindAllFreq(String str) {
var res = str.Select(x => x).Select(x => new ResultObject{Character = x, Frequency = str.Where(y => y == x).Count() }).ToList();