To print following series 1 3 9 27 81....n
Source Code
#include <iostream>
#include <iostream>
using namespace std;
void main ()
{
int i=1;
int ans=1;
int upperlimit;
cout<<"Please enter the uper limit :";
cin>>upperlimit;
while (i<=2 && ans<=upperlimit) // infinite loop and a conditional loop
{
cout<<ans<<"\t";
ans=ans*3;
}
}
Comments
Post a Comment