Answer to Question #277202 in C++ for Roe

Question #277202

Write c++ code that





(1)Please program to output all integers between 0 and 200 that are divisible by 3 and whose single digit is 6.




(2)run test the code in main

1
Expert's answer
2021-12-08T08:31:57-0500
#include<iostream>
using namespace std;


bool isDigitPresent(int a, int d)
{
    // Break loop if d is present as digit
    while (a > 0)
    {
        if (a % 10 == d)
            break;
 
        a = a / 10;
    }
 
    // If loop broke
    return (a > 0);
}
int main(){
	
	int i, d=6;;
	
	for(i=0;i<=200;i++){
		
		// checking for digit
        if ((i == d || isDigitPresent(i, d))  && i%3==0)
        {
        cout << i << " ";	
		}
            
		


	}
}

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