Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. About array??

About array??

Scheduled Pinned Locked Moved C#
data-structureshelptutorialquestion
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    omegazafer
    wrote on last edited by
    #1

    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?

    S J 2 Replies Last reply
    0
    • O omegazafer

      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?

      S Offline
      S Offline
      Sun Rays
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • O omegazafer

        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?

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #3

        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.

        O 2 Replies Last reply
        0
        • J J4amieC

          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.

          O Offline
          O Offline
          omegazafer
          wrote on last edited by
          #4

          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.

          J 1 Reply Last reply
          0
          • J J4amieC

            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.

            O Offline
            O Offline
            omegazafer
            wrote on last edited by
            #5

            Isn't there any response?

            L 1 Reply Last reply
            0
            • O omegazafer

              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.

              J Offline
              J Offline
              J4amieC
              wrote on last edited by
              #6

              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.

              O 1 Reply Last reply
              0
              • J J4amieC

                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.

                O Offline
                O Offline
                omegazafer
                wrote on last edited by
                #7

                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].

                1 Reply Last reply
                0
                • O omegazafer

                  Isn't there any response?

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  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


                  O 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    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


                    O Offline
                    O Offline
                    omegazafer
                    wrote on last edited by
                    #9

                    Sorry, I didn't understand your response.

                    L 1 Reply Last reply
                    0
                    • O omegazafer

                      Sorry, I didn't understand your response.

                      L Offline
                      L Offline
                      Luc Pattyn
                      wrote on last edited by
                      #10

                      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


                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups