Answer to Question #346479 in C++ for Babar azam

Question #346479

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.



1
Expert's answer
2022-06-01T12:54:56-0400
#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;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS