You need to write a program that reads in two integers from cin and outputs all of the integers between those values, except powers of three.
You can assume that the first value is strictly less than the second value.
#include <iostream> using namespace std; int main(){ int a, b, tmp; cout << "Enter two integers: "; cin >> a; cin >> b; for(int i=a;i<=b;i++){ //Checking i is a power of 3 tmp = i; while (tmp % 3 == 0) { tmp /= 3; } //Checking if i is not a power of 3 if(tmp!=1){ cout<<i<<" "; } } return 0; }
Get Answers For Free
Most questions answered within 1 hours.