Basic Programs

If Else based Programs

Loop Based Programs

Array Based Programs

String Programs

Function Programs

Pointers Programs

Structure & File Handling Programs

Data Structure Programs

Basic C Program

program to count freequency of elements in an array

#include <stdio.h>  
   
int main()  
{  
      
    int arr[20],fr[20],flag=-1,count=1,i=0,j=0; 
    
      printf("enter array elements\n");
      
      for(i=0; i<20; i++)
      {
      	scanf("%d",&arr[i]);
      	
	  }

      
    for(i = 0; i < 20; i++){  
        count = 1;  
        for(j = i+1; j < 20; j++){  
            if(arr[i] == arr[j]){  
                count++;  
                //To avoid counting same element again  
                fr[j] = flag;  
            }  
        }  
        if(fr[i] != flag)  
            fr[i] = count;  
    }  
      
    //Displays the frequency of each element present in array  
    printf("---------------------\n");  
    printf(" Element | Frequency\n");  
    printf("---------------------\n");  
    for(i = 0; i < 20; i++){  
        if(fr[i] != flag){  
            printf("    %d", arr[i]);  
            printf("    |  ");  
            printf("  %d\n", fr[i]);  
        }  
    }  
    printf("---------------------\n");  
    return 0;  
}  

Video/ C Introduction

Watch video in full size
Wordpress Social Share Plugin powered by Ultimatelysocial