Frequency of element in array

 // Online C++ compiler to run C++ program online

#include <iostream>

using namespace std;


void freq(int* arr,int n){

    int res=1;

    int i=0;

    while(i<n){

        if (arr[i]==arr[i+1]){

            res+=1;

        }

        else {

            cout<<arr[i]<<" "<<res;

            res=1;

            cout<<endl;

        }

        i++;

    }

}

int main() {

    int arr[10]={10,20,30};

    int n=3;

    freq(arr,n);


    return 0;

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings