Question

Write a C program that generates one hundred random integers between 0 and 9 and displays...

  1. Write a C program that generates one hundred random integers between 0 and 9 and displays the count for each number. (Hint: Use rand()%10 to generate a random integer between 0 and 9. Use an array of ten integers, say counts, to store the counts for the number of 0’s, 1’s,…..,9’s.)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//C program

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

int main(){
   srand(time(NULL));
  
   int counts[10];
   int i;
  
   for(i=0;i<10;i++)counts[i] = 0;
  
   for(i=0;i<100;i++){
       counts[rand()%10]++;
   }
  
   for(i=0;i<10;i++){
       printf("Count of %d = %d\n",i,counts[i]);
   }
   return 0;
}

//sample output

Add a comment
Know the answer?
Add Answer to:
Write a C program that generates one hundred random integers between 0 and 9 and displays...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT