Re: loops and arrays

  • From: "Littlefield, Tyler" <tyler@xxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 17 Oct 2007 13:49:44 -0600

srand(time(NULL)) is what I've always seen.
Tyler Littlefield.
Vertigo head coder
"My programs don't have bugs, just randomly added features."
msn: tyler@xxxxxxxxxxxxx
email: tyler@xxxxxxxxxxxxx
aim: st8amnd2005
----- Original Message ----- From: "Graham Hardy" <graham.hardy@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Wednesday, October 17, 2007 8:42 AM
Subject: RE: loops and arrays

Hi Daniel - I should point out that the rand () function works on an
algorithm based on a 'seed,' which is basically a number that you assign.
You assign the seed with the function void srand (int seed). If you don't
assign a seed, then it would use the seed of 1, which would end up
generating exactly the same sequence of random numbers from one time to the
next. This is also a good reason for not assigning a constant literal as a
seed either: it will still be the same from one runtime to the next. I
believe one convention is to get the current second, using a function in
time.h which I don't have the time to look at just now, and put that as your
seed. Another convention is that you usually don't want such long random
numbers. That is, you probably would want values between, say, 1 and 100, or
something like that. In this case, you would want to use the modulus
operator, as, x = 1 + (rand () % 100). I hope this is helpful. -Graham.

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Daniel Dalton
Sent: October 16, 2007 3:19 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: loops and arrays


Could someone help me out with this?
I have an array called array declared like this:
int array [5][4];
So I think this is called a multidimensional  array.

The book said I need to assign a random number to each array index.
(Using the rand library function.
In stlib.h)

I then have to print them to the screen.
In a table. From what I can understand 5 column's and 4 rows.
Should my code look something like this? It doesn't seem to work.
Could someone tell me where I am going wrong?

#include <stdio.h>
#include <stdlib.h>

int main ()
int array[5][4];
int a, b;

for(a =0; a < 5; a++)
for(b =0; b < 4; b++)
array [a][b] =rand ();

/*print them */
for(a =0; a <5; a++)
for(b =0; b < 4; b++)
/* I don't know what to do with this part.*/

Can someone help me finish it off? I have know idea how to get them to print
in the table.
Is there any other problems?

And one more question:
How do loops inside other loops work?
If I wrote:
for(i =0; i <200; i++)
for(x =0; x < 10; x++)
So would the loop with x (the loop inside the first loop) be executed while
the first loop is true?
So while the first loop is executing would it run the whole second loop for
one increment of I.
so would the second loop count up to 9 for every increment of i?

Thanks for any help.

Daniel Dalton
View the list's information and change your settings at

View the list's information and change your settings at

No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.488 / Virus Database: 269.14.13/1074 - Release Date: 10/16/2007 2:14 PM

View the list's information and change your settings at //

Other related posts: