Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Randomly generate an array of 100 integer numbers ranging from 100 to 999. (A) I

ID: 3879304 • Letter: R

Question

Randomly generate an array of 100 integer numbers ranging from 100 to 999.

(A) Identify the indexes of 3 largest numbers in the array using 3 variables. ( Use only comparisons. Cannot use sorting method for this request.)

(B) Identify the original indexes of ascending-sorted numbers in the array. You may use a sorting algorithm and another array for 100 indexes.

Display the original numbers using 10 lines with 10 numbers in each line. Then (A) answer and then (B) answer. Submit the C# codes and the cropping of the above results in a Word document.

==============Illustration===============

7 original random numbers: {23 14 36 72 15 18 12}

The original indexes: {0 1 2 3 4 5 6}

7 sorted numbers: {12 14 15 18 23 36 72}

The original indexes of sorted numbers: {6 1 4 5 0 2 3}

==============Output Example===============

Original Random numbers:

xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx

xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx
xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx
xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx
xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx
xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx
xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx
xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx
xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx
xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx

(A) The indexes of 3 largest numbers: xx, xx, xx

(B) The indexes of sorted numbers:

xx xx xx xx xx xx xx xx xx xx
xx xx xx xx xx xx xx xx xx xx
xx xx xx xx xx xx xx xx xx xx
xx xx xx xx xx xx xx xx xx xx
xx xx xx xx xx xx xx xx xx xx
xx xx xx xx xx xx xx xx xx xx
xx xx xx xx xx xx xx xx xx xx
xx xx xx xx xx xx xx xx xx xx
xx xx xx xx xx xx xx xx xx xx
xx xx xx xx xx xx xx xx xx xx

Explanation / Answer

using System;
class Program
{
static void Main()
{
int a, b, c, d;
for (int i = 1; i <= 1000; i++)
{
a = i / 100;
b = (i - a * 100) / 10;
c = (i - a * 100 - b * 10);
d = a * a * a + b * b * b + c * c * c;
if (i == d)
{
System.Console.WriteLine("{0}", i);
}
}
Console.Read();
}
}

public static int[] GenerateRandomNumbers()
{
//Initialize an integer variable
int num = 0;
//Initialize an int temp Array
int[] tempArr = new int[1001];
//Initialize an int array
int[] randomNum = new int[1001];
//Initialize random Number variable
Random rnd = new Random();


//Loop through to store Random Numbers to Array
for (int i = 0; i <= 1000; i++)
{


num = rnd.Next(1, 1000);
tempArr[i] = num;


//Insert only if the number is not already in the previouly
//generated vlaue
for (int j = 0; j < i; j++)
{
if (tempArr[j] != num)
{
randomNum[i] = num;
}
}
//output elements in Array
Console.WriteLine(num);
}


return randomNum;
}