Answer to Question #191882 in C++ for VASANTH V

Question #191882

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-11T10:00:14-0400
#include <iostream>
#include <string>
using namespace std;
int main(){
    int start = 200, stop = 2000, count = 0, count2 = 0;
    string s;
    cout<<"Enter the two integers\n";
    cin>>start; cin>>stop;
    for(int i = start; i <= stop; i++){
        count = 0;
        s = to_string(i);
        for(int j = 0; j < s.length(); j++) if(s[j] == '3') count++;
        if(count == 3) count2++;
    }
    cout<<count2;
    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