I'm making a small project using c# for my class. The program is
Ask user to enter an Integer value between 2 and 9. This value gives the maximum number of digits for random number I need to generate. For example, if the user enters a 7, then the maximum will be seven nines (9999999);
Create a random number between 10 and that maximum value. So, if user enters a 5, then the random number will be in range (10,99999]
After I created the random number, I need to create an array of digits for that number: for example, if the user enters a 3, then the random number is in (10,999]. Let's say it is 271. Then I need to generate an array of digits for 271, starting from right:
Array[0]=1
Array[1]=7
Array[2]=2
I tried to change the random number type to a string, so that I can determine the length of the array using that number:
Console.WriteLine("pleas enter value between 2 and 9");
string s = Console.ReadLine();
int v = int.Parse(s);
int v2=99, v3=999, v4=9999, v5=99999, v6=999999, v7=9999999, v8=99999999, v9=999999999;
if(v==2)
{
Console.WriteLine("Max number = " + v2);
Random randomNumber = new Random();
int number = randomNumber.Next(10, (++v2));
Console.WriteLine("random number " + number);
string sv =""+number;
string[] arry1 = new string [sv.Length];
Console.WriteLine("length array is :" + arry1.Length);
Console.WriteLine("array elements:"+ arry1[1]);
}else
{
if (v == 3)
{
Console.WriteLine("Max number = " + v3);
Random randomNumber = new Random();
int number = randomNumber.Next(10, (++v3));
Console.WriteLine("random number " + number);
string sv = "" + number;
string[] arry1 = new string[sv.Length];
Console.WriteLine("length array is :" + arry1.Length);
}
else
{
if(v==4)
{
Console.WriteLine("Max number = " + v4);
Random randomNumber = new Random();
int number = randomNumber.Next(10, (++v4));
Console.WriteLine("random number " + number);
string sv = "" + number;
string[] arry1 = new string[sv.Length];
Console.WriteLine("length array is :" + arry1.Length);
}
else ...
I am stuck on this step. How do I fill the array using the random number I have crated before?
This is how it should be:
I, however, can't use any external functions or methods.
question from:
https://stackoverflow.com/questions/65517646/create-random-number-and-make-an-array-from-that-number 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…