Miss Nosheen is a kindergarten teacher and is teaching numbers to her pupils. She wants to allow her students to be able to immediately verify the results of their answers to the problem of finding out the digits in a number. Write a program which can take a number and show the number of digits it contains.
#include <iostream>
#include <string>
using namespace std;
int main() {
string number;
int counter = 0;
cout << "Input number: ";
cin >> number;
cout << "In number " << number.size() << " digits" << endl;
for (int i = 0; i < 10; i++) {
counter = 0;
for (int j = 0; j < number.size(); j++) {
if ((number[j] - '0') == i) {
counter++;
}
}
cout << i << " - " << counter << " times" <<endl;
}
}
Comments
Leave a comment