Fill A 2D Array With Random Values | C Programming Example

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ม.ค. 2025

ความคิดเห็น • 22

  • @Omer-ys3ys
    @Omer-ys3ys 7 หลายเดือนก่อน

    Amazing video thank you

  • @hagimiguj7048
    @hagimiguj7048 2 ปีที่แล้ว +1

    If program is run multiple times within the same second - in loop, rand() will generate the same value because we're seeding with the same value. I am getting same values. Is there any way to fix this ?

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      Instead of running the program twice, you could call the function twice in the same program. On the second function call, the random values should be different.
      If this is not possible, there are other ways to create a seed that do not rely on the current time, for example:
      stackoverflow.com/a/7617612
      stackoverflow.com/a/7617686

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      I made this video to answer your question. :-) I hope you enjoy it: th-cam.com/video/zHZx9ByTo2s/w-d-xo.html

  • @سیاحتِکشمیروپاکستان
    @سیاحتِکشمیروپاکستان 2 ปีที่แล้ว +1

    create 3 x3 matrixin 2 d array.each cell of a matrix is filled with unique random no between 1 to 50(use random function).the user can see random value hiden in matrx

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      Did this video help you with this question, or are you stuck on it?

  • @kasparovmarconi2608
    @kasparovmarconi2608 3 ปีที่แล้ว +1

    This is usefull, thanks bro

  • @Roadieroundup
    @Roadieroundup 2 ปีที่แล้ว

    what if i don't want to repeat numbers?

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว +2

      This video shows how to fill a 1D array with unique random numbers: th-cam.com/video/wnjYD_euSJQ/w-d-xo.html.
      One easy way to fill a 2D array would be to generate the unique numbers in a 1D array that is m x n in length, where m is the number of rows and n is the number of columns in the 2D array, then you could just copy the values over to the 2D array in a loop nested in a loop like this:
      int k = 0;
      for (int i = 0; i < m; i++)
      for (int j = 0; j < n; j++)
      array2d[i][j] = array1d[k++];
      This would essentially let you use the code in the video I linked to above.
      Otherwise, you could do it in a way that is pretty similar to the solution I linked to above, but you would need a loop nested in a loop setting each value, and another loop nested in a loop to check if the new random value to see if it is in the previous values. Maybe one day I can make a video on that. :-)

    • @Roadieroundup
      @Roadieroundup 2 ปีที่แล้ว

      @@PortfolioCourses thanks, i will try it

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว +1

      @@Roadieroundup You're welcome! 🙂

  • @furkansaifi4613
    @furkansaifi4613 2 ปีที่แล้ว +1

    Please make a video of 2D array filled with unique random values 🙏

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      I am hoping to do a video on that topic one day Furkan! :-) In the meantime I have this video on doing this with 1D arrays that might give you some ideas: th-cam.com/video/wnjYD_euSJQ/w-d-xo.html

  • @abdullahnadeem1522
    @abdullahnadeem1522 2 ปีที่แล้ว

    thanks mate

  • @ryanalnaser914
    @ryanalnaser914 2 ปีที่แล้ว

    whatever anything I do or did or anything or know or knew or did not know or knew