The following program generates fifty random integers in the range of 1 to 40 in
ID: 3635967 • Letter: T
Question
The following program generates fifty random integers in the range of 1 to 40 inclusive for the array: a and displays them on the screen. Extend the program to display how many occurrences of each number are generated in the range 1-10, 11-20, 21-30, and 31-40. the execution has to be like the following after u complete the program.37, 36, 24, 36, 36, 40, 12, 30, 36, 10, 13, 20, 5, 15, 39, 37, 7, 4, 40, 27, 11, 13, 10, 39, 15, 12, 7, 28, 39, 12, 13, 15, 24, 38, 2, 5, 22, 28, 17, 6, 1, 20, 29, 25, 11, 32, 22, 39, 5, 35,
In the ragne 1-10 there are: 11
In the ragne 11-20 there are: 14
In the ragne 21-30 there are: 10
In the ragne 31-40 there are: 15
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(){
int a[50], i; //You may need to declare more variables
srand((unsigned)time(NULL));
for(i = 0; i < 50; i++){
a[i] = rand() % 40 + 1;
printf("%d, ", a[i]);
}
printf(" ");
//Write your code below
}
Explanation / Answer
Need to create an array to keep track of where each number falls as it is generated. #include #include #include int main(){ int a[50]; //You may need to declare more variables int count[5] = {0,0,0,0,0}; int i; int j; srand((unsigned)time(NULL)); for(i = 0; i < 50; i++){ a[i] = rand() % 40 + 1; printf("%d, ",a[i]); if (a[i]Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.