Posts

Showing posts from November 22, 2018

C: Create randomly-generated integers, store them in array elements, and print number of integers stored in...

Image
up vote 0 down vote favorite 1 I'm incredibly new to C (and programming in general) and finding how to manipulate arrays is almost impossible to understand (I know what an array is). I'm attempting to write a program that generates 100 random integers in a range (1-50) , stores them in array elements (1-10, 11-20, 21-30, 31-40, and 41-50), and print the number of randomly generated integers stored in each element, i.e. 1-10 = 20 11-20 = 30 21-30 = 21 31-40 = 19 41-50 = 20 The best I can come up with so far is: void randomNumbers { int count[ARRAY_LENGTH]; for (int i = 0; i < ARRAY_LENGTH; i++) { count[i] = 0; } for (int i = 0; i < ARRAY_LENGTH; i++) { count[i] = rand() % 50 + 1; } for (int i = 0; i <= ARRAY_LENGTH - 1; i++) {