WAP to find frequency of element in C

 Here is your code in C -

#include <stdio.h>

int main()
{
    int a[5], i, freq=0, key;
    
    printf("Enter the elements of array: ");
    
    for (i=0; i<5; i++) {
        scanf("%d", &a[i]);
    }
    
    printf("Enter the element whose frequency you want to find: ");
    
    scanf("%d", &key);
    
    for (i=0; i<5; i++) {
        if (key == a[i])
        freq ++;
    }
    
    printf("\nFrequency of %d is %d", key, freq);
 
    return 0;
}


Output -



Comments

Popular posts from this blog

WAP that inputs two arrays and saves sum of corresponding elements of these arrays in a third array

WAP to add or to multiply two matrices of order nXn.

WAP that swaps values of two variables without third variable.