Basics in arrays, c++.

I'm a beginner in c++ and i have been given a project to do in c++. It may look easy to a person that has been doing this for a long time but I am still learning.

I have to create a two dimensional array[5][5] with random numbers from 0 to 20, i should first print the numbers in the array on the screen and then find the sum of all of them. Also i should use the srand function with #include <time.h>.
Can i have you guys' help. Thanks in advance!
Thank you for the link but how do i assign each number in the array to the srand function so each of the is random.
Just call rand() % 21; for each element in the array
I'll just drop this link in here as I see you're using a two dimensional array.

Cheers for the replies guys! I just declare srand like srand(time(NULL)) and use the rand feature, all sorted for now!
About random,
the srand() function will randomize the seed (seed-randomize). This operation will make the numbers generated by rand() more random.
When you're debugging, you may not want to call "srand()". Doing so will make every execution give you the exact same random numbers.
(so if you find some errors, without srand you can replicate the same situation, while with srand numbers will change and the error may not occur again)
Last edited on
Registered users can post here. Sign in or register to post.