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