Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In a main function declare an array of 1000 ints. Fill up the array with random numbers that represent the rolls of a die. That

In a main function declare an array of 1000 ints.

Fill up the array with random numbers that represent the rolls of a die. That means values from 1 to 6.

Write a loop that will count how many times each of the values appears in the array of 1000 die rolls.

Use an array of 6 elements to keep track of the counts, as opposed to 6 individual variables.

Print out how many times each value appears in the array.

1 occurs XXX times

2 occurs XXX times

my code

#include

#include

#include

int main()

{

int array[1000];

int x;

int sum[6];

srand(time(NULL));

for(x=0; x<1000; x++){

array[x]= (int)(rand()%6+1);

sum[array[x]]=(sum[array[x]]++);

}

for(x=1; x<7; x++){

printf("%d occured %d times. ", x , sum[6]);

}

return 0;

}

output

The dice rolled a 1, 1384960 times. The dice rolled a 2, 1384960 times. The dice rolled a 3, 1384960 times. The dice rolled a 4, 1384960 times. The dice rolled a 5, 1384960 times. The dice rolled a 6, 1384960 times.

i need help fixing this error

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2019 Wurzburg Germany September 16 20 2019 Proceedings Part 2 Lnai 11907

Authors: Ulf Brefeld ,Elisa Fromont ,Andreas Hotho ,Arno Knobbe ,Marloes Maathuis ,Celine Robardet

1st Edition

3030461467, 978-3030461461

More Books

Students also viewed these Databases questions