About array??
-
Hello friends, I want to construct an array which consist of 9 members.,(for example int[] sayilar=new int[9]) We construct the array members randomly. The members of array must be between the number of 1 and 9. and The values of sayilar[1] musn't be valuef sayilar[2] and the value of sayilar[4] musn't be value of sayilar[6]. For example, we give 7 to sayilar[1] as randomly, sayilar[2] must be different from 7. Can you help me?
-
Hello friends, I want to construct an array which consist of 9 members.,(for example int[] sayilar=new int[9]) We construct the array members randomly. The members of array must be between the number of 1 and 9. and The values of sayilar[1] musn't be valuef sayilar[2] and the value of sayilar[4] musn't be value of sayilar[6]. For example, we give 7 to sayilar[1] as randomly, sayilar[2] must be different from 7. Can you help me?
Hi, when yu are assigning any value to array then you have to chekc whether that new string contains in array or not. If not then add else give message that value is there in list. iArr[4].ToString() == iArr[2].ToString() then dont add value.
Thanks, Sun Rays To get something you must have to try once. My Articles
-
Hello friends, I want to construct an array which consist of 9 members.,(for example int[] sayilar=new int[9]) We construct the array members randomly. The members of array must be between the number of 1 and 9. and The values of sayilar[1] musn't be valuef sayilar[2] and the value of sayilar[4] musn't be value of sayilar[6]. For example, we give 7 to sayilar[1] as randomly, sayilar[2] must be different from 7. Can you help me?
Sounds like homework. In order to get help with homework you need to show willing to have a try yourself and ask questions when you get stuck. Nobody is going to write the code for you. I can give you some tips to get started. 1) Fill a list with the 9 possible values 2) Get a random number between 0-8 3) Get this item out of the list (remember to remove it) and add it to position 0 in the Array 4) Get a random number between 0-7 5) Get this item out of the list (remember to remove it) and add it to position 1 in the Array 6) Rinse/repeat until the array is full.
-
Sounds like homework. In order to get help with homework you need to show willing to have a try yourself and ask questions when you get stuck. Nobody is going to write the code for you. I can give you some tips to get started. 1) Fill a list with the 9 possible values 2) Get a random number between 0-8 3) Get this item out of the list (remember to remove it) and add it to position 0 in the Array 4) Get a random number between 0-7 5) Get this item out of the list (remember to remove it) and add it to position 1 in the Array 6) Rinse/repeat until the array is full.
Random rnd = new Random(); int[] sayilar = new int[9]; for (int i = 0; i < 9; i++) { int rastgele = rnd.Next(1, 9); sayilar[i] = rastgele; } Above, I can construct the array members randomly but, my problem is that, For example, I gave 7 to sayilar[1], after that I can't remove 7 from number list. Because the sayilar[2] can't be 7 but the others members of array can be 7. My condition is not that all members have different values , I want only sayilar[1] is different from sayilar[2] and sayilar[4] is different from sayilar[5]. sayilar[7],sayilar[8],sayilar[6],sayilar[3] can have the same value. I give numbers to members as randomly.
-
Sounds like homework. In order to get help with homework you need to show willing to have a try yourself and ask questions when you get stuck. Nobody is going to write the code for you. I can give you some tips to get started. 1) Fill a list with the 9 possible values 2) Get a random number between 0-8 3) Get this item out of the list (remember to remove it) and add it to position 0 in the Array 4) Get a random number between 0-7 5) Get this item out of the list (remember to remove it) and add it to position 1 in the Array 6) Rinse/repeat until the array is full.
Isn't there any response?
-
Random rnd = new Random(); int[] sayilar = new int[9]; for (int i = 0; i < 9; i++) { int rastgele = rnd.Next(1, 9); sayilar[i] = rastgele; } Above, I can construct the array members randomly but, my problem is that, For example, I gave 7 to sayilar[1], after that I can't remove 7 from number list. Because the sayilar[2] can't be 7 but the others members of array can be 7. My condition is not that all members have different values , I want only sayilar[1] is different from sayilar[2] and sayilar[4] is different from sayilar[5]. sayilar[7],sayilar[8],sayilar[6],sayilar[3] can have the same value. I give numbers to members as randomly.
Go back and read my tips. You need an Array and a List. The list contains the available numbers, once a number is used it is removed from the list. This is a very easy problem and just needs some thought on how to not duplicate the numbers into the destination array.
-
Go back and read my tips. You need an Array and a List. The list contains the available numbers, once a number is used it is removed from the list. This is a very easy problem and just needs some thought on how to not duplicate the numbers into the destination array.
I can't explain my question. Removing is not right way for me because the number ,used for sayilar[1], can be used other members of array only can't be used forsayilar[2].
-
Isn't there any response?
foreach number required {
forever {
generate a random number;
if you like it {
store it;
break;
}
}
}:)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets
-
foreach number required {
forever {
generate a random number;
if you like it {
store it;
break;
}
}
}:)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets
Sorry, I didn't understand your response.
-
Sorry, I didn't understand your response.
it basically says "if you don't like a random number, roll the dices again".
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets