0

Hello all. Anywho ive been studying c now for a few weeks, and up until now it has not been too steep of a learning curve for me but that has changed recently. My problem is basically that i need to create an array with 50 random integers using srand() . Now i've determined that the easiest way to do this is to use a for loop. However i'm unsure as to how i would set up this for loop so that it does all 50 integers within the array.
Any help would be greatly appreciated.
Thanks!

3
Contributors
3
Replies
5
Views
10 Years
Discussion Span
Last Post by Aia
0
/*
 * Giveme50.c
 * Show how to assign random integer into array.
 */

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

int main( void )
{
    int fifty[50];
    int i;
    
    srand( (unsigned ) time( NULL ) );
    
    for( i = 0 ; i < 50; i++ )
    {
        fifty[i] = rand();
    }
    
    for( i = 0; i < 50; i++ )
    {
        printf( "%d\n", fifty[i] );
    }
    
    getchar();
    return 0;
}
Votes + Comments
Balance++
I'm Rashakil Fol and I disapprove of this message.
0

Of course I could have ask it to give me a `croissant and a cup of coffee'. But I didn't. On purpose.
The thing I would change is the `magic number' 50.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.