write a in c++ 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
If you were to enter 5 and 30 you would get
6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,28
so I’m not sure how to get rid of the powers of 3, so 3^1, 3^2 ... etc
#include <iostream> using namespace std; int main(){ int n1, n2, n; cout<<"Enter two integers: "; cin>>n1; cin>>n2; for(int i = n1+1;i<n2;i++){ n = i; while (n % 3 == 0) { n /= 3; } if(n!=1){ cout<<i<<" "; } } return 0; }
Get Answers For Free
Most questions answered within 1 hours.