C program to find frequency of a number in array

Hello, Student today you will learn to find the frequency of a Number in an Array. With help of this code, you will understand, How actually works Random number Frequency in C languages while using Array.

To understand this Program, you should have knowledge of the following topics in Array

Frequency program in C

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

int random_value (void){

int randon_number = (int) (10.0*rand()/(RAND_MAX + 1.0));

return (randon_number);
}
int main()
{
srand(time(0));

int numbers[10]={0,1,2,3,4,5,6,7,8,9},freq=0,i,j,key;

int array[10000];

array [0] = 0;

//Entry of digits

for (i=0;i<10000;i++){

array[i] = random_value();

}

//0 to 9 digit taking

for(i=0;i<10;i++){

numbers[i] = random_value();

key = numbers[i];

}

// frequency count

for (i=0;i<10000;i++){

if (array[i]==key)

freq++;
}
printf("The frequency of %d is : %.2f percent ",key,(float)freq/100);
return 0;
}
OUTPUT
The frequency of 4 is: 9.53 percent
C program to find frequency of a number in array
C program to find frequency of a number in array
IT will change all the time, Or It will generate a Random Number all the time Saurabh Nissa

 

if u call the function without ( ), it is like returning the address of the function.

END

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.