write a c program to solve the following problem Upload your

write a c program to solve the following problem. Upload your source code file to Canvas. The file name must be of the form hwarray your name.c substitute your first and last name for your name\" in the file name. Example: Student\'s name is Sparky Watts. The file name is hwarray sparky watts.c Problem Statement Create a program that displays a frequency histogram. The program output should closely resemble the example output shown below. CAUsersDianelDesktophistogrambinNDebughistogramexe Histogran Group 0 Group Group 2 Group 3: Group 4: Group S: Group 6 Group 7 up 8 9 Group Most frequent nunber: 29. occurs Stines Process returned 0 (0x0) execution tine 0.570 s Press any key to continue. The above output represents a count of generated random numbers. The range of random numbers is [0,991, inclusive. In the above example, 150 random numbers were generated. The data is split into 10 equal groups. Range Group Group Range [50, 59] [0,9] (60, 69] [10, 19] [70, 79] [20, 29]

Solution

#include <stdio.h>

int main()
{
int frequencies[10][10];
int i,j;
  
//Initializing all the number frequencies to 0
for(i=0;i<10;i++){
for(j=0;j<10;j++){
frequencies[i][j] = 0;   
}
}
  
int generate = 150;
srand(time(NULL));
  
//Generaing 150 random numbers
while(generate!=0){
  
int number = rand()%100;
//increasing the frequency of generated number
frequencies[number/10][number%10] = frequencies[number/10][number%10]+1;
generate--;
}
  
int max = 0;
int maxNumber = 0;
for(i=0;i<10;i++){
int sum = 0;
//Calculating the sums of groups
for(j=0;j<10;j++){
sum += frequencies[i][j];
if(max<frequencies[i][j]){
max = frequencies[i][j];
maxNumber = i*10+j;
}
}
printf(\"Group %d\",i*10);
//printing the asterisk
for(j=0;j<sum;j++){
if(j%10 == 0){
printf(\"\ \");
}
printf(\"%c\",\'*\');
}
printf(\"\ \");
}
printf(\"Number: %d occured %d times. This is maximum occured number\ \",maxNumber,max);
return 0;
}

Output:

sh-4.2$ main                                                                                                                                                    

Group 0                                                                                                                                                         

********                                                                                                                                                        

Group 10                                                                                                                                                        

*********                                                                                                                                                       

Group 20                                                                                                                                                        

**********                                                                                                                                                      

**********                                                                                                                                                      

Group 30                                                                                                                                                        

**********                                                                                                                                                      

*******                                                                                                                                                         

Group 40

**********                                                                                                                                                      

*                                                                                                                                                               

Group 50                                                                                                                                                        

**********                                                                                                                                                      

**********                                                                                                                                                      

*                                                                                                                                                               

Group 60                                                                                                                                                        

**********                                                                                                                                                      

****                                                                                                                                                            

Group 70                                                                                                                                                        

**********                                                                                                                                                      

*****                                                                                                                                                           

Group 80                                                                                                                                                        

**********                                                                                                                                                      

**********                                                                                                                                                      

Group 90   

**********                                                                                                                                                      

*****                                                                                                                                                           

Number: 51 occured 5 times. This is maximum occured number   

 write a c program to solve the following problem. Upload your source code file to Canvas. The file name must be of the form hwarray your name.c substitute your
 write a c program to solve the following problem. Upload your source code file to Canvas. The file name must be of the form hwarray your name.c substitute your
 write a c program to solve the following problem. Upload your source code file to Canvas. The file name must be of the form hwarray your name.c substitute your

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site