Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

Program for frequency counting

Posted By: Louis Evans     Category: C Programming     Views: 6364

Program for frequency counting.

Code for Program for frequency counting in C Programming

#define   MAXVAL    50                                      
   #define   COUNTER   11                                    
   main()                                                      
   {                                                           
       floatvalue[MAXVAL];                             
       int          i, low, high;                              
       int   group[COUNTER] = {0,0,0,0,0,0,0,0,0,0,0};  
  /* . . . . . . . .READING AND COUNTING . . . .  . .*/
for( i = 0 ; i < MAXVAL ; i++ ) { /*. . . . . . . .READING OF VALUES . . . . . . . . */
scanf("%f", &value[i]) ; /*. . . . . .COUNTING FREQUENCY OF GROUPS. . . . . */
++ group[ (int) ( value[i] + 0.5 ) / 10] ; } /* . . . .PRINTING OF FREQUENCY TABLE . . . . . . .*/
printf("\n"); printf(" GROUP RANGE FREQUENCY\n\n") ; for( i = 0 ; i < COUNTER ; i++ ) { low = i * 10 ; if(i == 10) high = 100 ; else high = low + 9 ; printf(" %2d %3d to %3d %d\n", i+1, low, high, group[i] ) ; } } Output 43 65 51 27 79 11 56 61 82 09 25 36 07 49 55 63 74 81 49 37 40 49 16 75 87 91 33 24 58 78 65 56 76 67 45 54 36 63 12 21 73 49 51 19 39 49 68 93 85 59 GROUP RANGE FREQUENCY 1 0 to 9 2 2 10 to 19 4 3 20 to 29 4 4 30 to 39 5 5 40 to 49 8 6 50 to 59 8 7 60 to 69 7 8 70 to 79 6 9 80 to 89 4 10 90 to 99 2 11 100 to 100 0 [/Code]
  
Share: 


Didn't find what you were looking for? Find more on Program for frequency counting Or get search suggestion and latest updates.

Louis Evans
Louis Evans author of Program for frequency counting is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
Sanjay Dutta from India Comment on: 14:37 hrs ago
i am trying to find the frequency of real random number generated. It shows no error but do not give the desire result.
Here is the code
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{

int i,n=0;
float randomNumber;
float array_1[101] ;

srand ((unsigned) time(NULL));
for(i = 1; i<100; i++)
{
randomNumber = (rand() %100) ;
printf("Index[%d] = %f\n",i,randomNumber);
array_1[i]=randomNumber++;
for (i=1;array_1[i]<100;i++)
{
if(randomNumber==array_1[i])
++n;
}
for (i=0;i<100;i++)
{
printf("The number [%f] has been randomly generated[%d]times \n",array_1[i],n);
return 0;
}
}
}

View All Comments