Answer to Question #191871 in C++ for Rock

Question #191871

PLATE GAME USING FUNCTIONS


Plate Game


In Sachin's birthday party, he organize a game, in which numbered plates are hanged on the wall. We have to hit by a ball on plate, if the plate numbered having exactly three three's in it, you win game.


Write a program, to count the numbers from range(both the numbers inclusive), which have exactly three three's.


Input Format:


A line corresponds to 2 integer which represents range (both are inclusive). Default integer is 200 and 2000,


Output format:


A line corresponds to a integer which represents the count of numbers which is having exactly three three's in it.


1
Expert's answer
2021-05-13T23:25:28-0400
#include <iostream>
#include <string>


using namespace std;
int countNumThree3(int n1, int n2){
    string s;
    int count_digits=0, count_numbers=0;
    for(int i=n1;i<=n2;i++){
        s=to_string(i);
        count_digits=0;
        for(int j=0;j<s.length();j++){
            if (s[j]=='3'){
                count_digits++;
            }
        }
        if (count_digits==3){
            count_numbers++;
        }
    }
    return count_numbers;
}
int main()
{
    int start=200;
    int stop=2000;
    cout<<"Enter the starting number: ";
    cin>>start;
    cout<<"Enter the stopping number: ";
    cin>>stop;
    int n=countNumThree3(start,stop);
    cout<<n;
    return 0;
}

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