Use a while loop to find the smallest integer n such that 3n is greater than 30000
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
//Use a while loop to find the smallest integer n such that 3^n //is greater than 30000
int n=0;
int threePow=1;
while(threePow<=30000)
{
threePow*=3;
n++;
}
cout<<"The smallest n: "<<n<<endl;
cout<<"3^"<<n<<"="<<threePow<<endl;
cout<<"3^"<<n-1<<"="<<threePow/3<<endl;
return 0;
}
//An easy program I don't think understand code hardly for you
Comments
Leave a comment