Utopian Tree height in C#

The Utopian Tree goes through 2 cycles of growth every year. The first growth cycle occurs during the spring, when it doubles in height. The second growth cycle occurs during the summer, when its height increases by 1 meter.

Now, a new Utopian Tree sapling is planted at the onset of spring. Its height is 1 meter. Can you find the height of the tree after N growth cycles?
Input Format:
The first line contains an integer, T, the number of test cases.
T lines follow; each line contains an integer, N, that denotes the number of cycles for that test case.
Constraints
1≤T≤10
0≤N≤60
Output Format:
For each test case, print the height of the Utopian Tree after N cycles. Each line thus has to contain a single integer, only.
Sample Input:
3
0
1
4
Sample Output:
1
2
7

 

class Utopian_Tree_Height
{
static void Main(string[] args)
{
int totalCycles = Convert.ToInt32(Console.ReadLine());
int currentHight;
for (int i = 0; i < totalCycles; ++i)
{
currentHight = 1;
int currentCycle = Convert.ToInt32(Console.ReadLine());
for (int j = 1; j <= currentCycle; ++j)
{
if (j % 2 == 0)
{
currentHight += 1;
}
else
{
currentHight *= 2;
}
}
Console.WriteLine(currentHight);
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s