Utopian Tree | Hackerrank Solution in C++
Utopian Tree | Hackerrank Solution
It is an hackerrank problem you can find it by clicking here. Below given solution is prepared by one of the coder of our. Soultion in C++
#include<iostream>
using namespace std;
int main(){ int n; cin>>n; for(int i=0;i<n;i++) { int h=1; int c; cin>>c; for(int j=1;j<=c;j++) { if(j%2!=0) { h = h*2; } if(j%2==0) { h=h+1; } } cout<<h<<endl; } return 0;}
It is an hackerrank problem you can find it by clicking here.
Below given solution is prepared by one of the coder of our.
Soultion in C++
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
int h=1;
int c;
cin>>c;
for(int j=1;j<=c;j++)
{
if(j%2!=0)
{
h = h*2;
}
if(j%2==0)
{
h=h+1;
}
}
cout<<h<<endl;
}
return 0;
}

Comments
Post a Comment