Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following program generates fifty random integers in the range of 1 to 40 in

ID: 3633787 • 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.

#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 the code here ?
}

Explanation / Answer

please rate - thanks

#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
int count[10];
srand((unsigned)time(NULL));
for(i = 0; i < 50; i++){
     a[i] = rand() % 40 + 1;
      printf("%d, ", a[i]);
     }
printf(" ");

//Write the code here ?
for(i=0;i<10;i++)
     count[i]=0;
for(i=0;i<50;i++)
    count[(a[i]-1)/10]++;
printf("range count ");
for(i=0;i<4;i++)
   printf("%d-%d %d ",i*10+1,(i+1)*10,count[i]);
getch();
return 0;
}