C Program To Find The Frequency Of A Number

How to write a C Program To Find The Frequency Of A Number in C Programming Language ?


Solution For C Program :

/*C Program To Find The Frequency Of A Number.*/

#include<stdio.h>
#include<conio.h>
void main()
    {
    int num,i,arr[5],count1=0,count2=0,flag=0;
    printf("Enter 5 numbers for array:=");
    for(i=0;i<5;i++)
        {
        scanf("%d",&arr[i]);
        }
    printf("Enter number to find the frequency:=");
    scanf("%d",&num);
    for(i=0;i<5;i++)
        {
        if(arr[i]==num)
            {
            count1++;
            flag=1;
            }
        }
        if(flag==1)
            {
            printf("frequency of %d := %d\n",num,count1);
            }
        for(i=0;i<5;i++)
            {
            if(arr[i]!=num)
                {
                count2++;
                }
            }
        if(count2==5)
            {
            printf("Number %d does not exist in present array",num);
            }
        getch();
    }

You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable


Learn More :