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.
#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;
}
Comments
Leave a comment