0% found this document useful (0 votes)
10 views4 pages

C++ Program for Digit Frequency Count

The document contains a C++ program that reads integers from a file, counts the frequency of each digit, and then processes these digits to form a new number. It sorts the digits and ensures that the first digit is not zero before outputting the final number if it is odd. The results are written to an output file.

Uploaded by

Andrei Petrea
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

C++ Program for Digit Frequency Count

The document contains a C++ program that reads integers from a file, counts the frequency of each digit, and then processes these digits to form a new number. It sorts the digits and ensures that the first digit is not zero before outputting the final number if it is odd. The results are written to an output file.

Uploaded by

Andrei Petrea
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include <iostream>

#include <fstream>

using namespace std;

ifstream f("[Link]");

ofstream g("[Link]");

int a[1000],b[10],i,j,aux,n,nr,nrcifre,cifre,cif;

int main()

i=0;

while(f>>a[i])

while(a[i]!=0)

cif=a[i]%10;

b[cif]++;

a[i]/=10;

i++;

i=0;

for(cif=9; cif>=0; cif--)

while(b[cif]!=0)

g<<cif<<" ";

i++;

b[cif]--;

while(n)
{

nrcifre++;

cifre[nrcifre]=n%10;

n/=10;

for(i=1; i<nrcifre; i++)

for(j=i+1; j<=nrcifre; j++)

if(cifre[i]>cifre[j])

aux=cifre[i];

cifre[i]=cifre[j];

cifre[j]=aux;
}

int ok=0;

if(cifre[1]==0)

i=1;

while(cifre[i]==0)i++;

int aux=cifre[1];

cifre[1]=cifre[i];

cifre[i]=aux;

for(i=1; i<=nrcifre; i++)

nr=nr*10+cifre[i];

}
else

for(i=1; i<=nrcifre; i++)

nr=nr*10+cifre[i];

if(nr%10%2==1)

cout<<nr;

g<<endl;

return 0;

You might also like