Original Post
🔒 Locked
C array problem
Advertisement
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.
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;
}
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;
}
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
Quote:Yes, learn how to tell whether an integer is even or odd.
Original post by rawezkyi
any pointers here please?}
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement