Computer Science, asked by mohammadarshu20, 1 month ago

write a c program to read an integer number from the user and count frequency of digits in given number
in c or c++ language

Answers

Answered by anindyaadhikari13
10

\textsf{\large{\underline{Solution}:}}

The given problem is solved using language - C++.

#include <iostream>

using namespace std;

int main() {

   int n,i;

   cout<<"Enter a number: ";

   cin>>n;

   cout<<"\nGiven Number: "<<n<<endl;

   int arr[]={0,0,0,0,0,0,0,0,0,0};

   for(;n!=0;n/=10)

       arr[n%10]++;

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

       if(arr[i]!=0)

           cout<<"Frequency of "<<i<<" is: "<<arr[i]<<endl;

   }

   return 0;

}

\textsf{\large{\underline{Explanation}:}}

  • The array stores the frequency of every digit (0-9).
  • The frequency of every digit present in the number is display using loop.

See the attachment for output.

Attachments:
Similar questions