Skip to main content
gamedev.net
🔒 Locked

C array problem

Started by rawezkyi 6 replies 600+ views
Original Post
rawezkyi
rawezkyi
Hello,


im new to programming and would appreciate any help with my problem.
I need to load an array(in C) of 25 random numbers between 10 and 99.

thanks in advance
Zakwayda
Zakwayda
Is this a homework problem?
ArthY303
ArthY303
Hello ! You can truly learn a programming language only by trying out different things on your own. Post what you have so far, and you will get pointed in the right direction.
phresnel
phresnel
Quote:
Original post by rawezkyi
Hello,


im new to programming and would appreciate any help with my problem.
I need to load an array(in C) of 25 random numbers between 10 and 99.

thanks in advance


In pseudo code:

    foobars : array of int    for all foobar in foobars        foobar = random (10..99)


If you have problems, report back and state what you have tried.
rawezkyi
rawezkyi
So, with a lot of help I managed to create and print an array of 25 random numbers ranging from 1-99, my next problem is to copy even numbers from that array into another array and print that aswell.

any pointers here please?

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


#define MAX 99
static int seen[MAX];

static int nmb[25];


int main (void) {
int i;

srand(time(NULL));

for (i=0; i<25; i++) {
int r;
do {
r = rand() / (RAND_MAX / MAX + 1);
} while (seen[r]);
seen[r] = 1;
nmb = r + 1;
}
printf("Prvo polje: \n");
for (i=0; i<25; i++)
printf("%i\n", nmb);

return 0;
}
Palidine
Palidine
Quote:
Original post by rawezkyi
So, with a lot of help I managed to create and print an array of 25 random numbers ranging from 1-99, my next problem is to copy even numbers from that array into another array and print that aswell.


come on, dude. post what you've already tried and how it failed. we're not going to do your homework for you if you're putting zero effort into it.

-me

nobodynews
nobodynews
Quote:
Original post by rawezkyi
any pointers here please?}
Yes, learn how to tell whether an integer is even or odd.
C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) ,

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.