Se citeste un nr x. Sa se afiseze:
. b. cate cifre are;
c. cate cifre pare/impare are;
d. media aritmetica a cifrelor;
e. de cate ori apare o cifra in x.
urgent :(
Răspunsuri la întrebare
#include <iostream>
using namespace std;
short c[10];
int main()
{
int x, nrcif=1, cifrepare=0, cifreimpare=0, sumacif=0, cif;
float media=0;
cin >> x;
if (x==0)
{
++cifrepare; c[0]=1;
}
else
{
int cif;
nrcif=0;
while (x)
{
cif=x%10; ++nrcif;
++c[cif];
if (cif%2==0) ++cifrepare;
else ++cifreimpare;
sumacif+=cif;
x/=10;
}
}
cout << "Raspuns: " << "\n";
cout << "numarul are "<<nrcif<<" cifre" << "\n";
cout << "numarul are "<<cifrepare<<" cifre pare" << "\n";
cout << "numarul are "<<cifreimpare<< " cifre inpare" << "\n";
media=(float)sumacif/nrcif;
cout << "media aritmetica a cifrelor="<<media<<"\n";
cout << "frecventa de aparite a cifrelor in numarul dat"<<"\n";
for (cif=0; cif<=9; ++cif)
if (c[cif])
cout << "cifra "<<cif<<" - de "<<c[cif]<< " ori" << "\n";
cout << " S U C C E S E !";
return 0;
}