Написать программу в С++ Дано натуральное число. Определить, сколько раз в нём встречается максимальная цифра.
Answers & Comments
UnS1asher
#include <iostream> using namespace std; int A[20];
int main() { int n, c, p, max; int counter, ncounter; counter = 0; cin >> n; c = n; p = n; for (c; c>0;) { counter++; c = c / 10; A[counter] = p - c * 10; p = c; if (c > 0 && c < 10) { A[counter + 1] = c; } } max = 0; ncounter = 0; for (int s = 1; s <= counter; s++) { if (A[s] > max) { max = A[s]; ncounter = 0; } if (A[s] == max) { ncounter++; } } cout << ncounter; system("pause"); return 0; }
Answers & Comments
using namespace std;
int A[20];
int main()
{
int n, c, p, max;
int counter, ncounter;
counter = 0;
cin >> n;
c = n;
p = n;
for (c; c>0;)
{
counter++;
c = c / 10;
A[counter] = p - c * 10;
p = c;
if (c > 0 && c < 10)
{
A[counter + 1] = c;
}
}
max = 0;
ncounter = 0;
for (int s = 1; s <= counter; s++)
{
if (A[s] > max)
{
max = A[s];
ncounter = 0;
}
if (A[s] == max)
{
ncounter++;
}
}
cout << ncounter;
system("pause");
return 0;
}