Hacker Rank Solution For Utopian-Tree

Utopian-Tree

The Utopian tree goes through 2 cycles of growth every year. The first growth cycle of the tree occurs during the monsoon, when it doubles in height. The second growth cycle of the tree occurs during the summer, when its height increases by 1 meter.
Now, a new Utopian tree sapling is planted at the onset of the monsoon. 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.

Sample Input #00:
2
0
1

Sample Output #00:

1
2
Explanation #00:
There are 2 test cases. When N = 0, the height of the tree remains unchanged. When N = 1, the tree doubles its height as it's planted just before the onset of monsoon.


Sample Input: #01:

2
3
4

Sample Output: #01:

6
7

Explanation: #01: 

There are 2 testcases.
N = 3:
the height of the tree at the end of the 1st cycle = 2
the height of the tree at the end of the 2nd cycle = 3
the height of the tree at the end of the 3rd cycle = 6

N = 4:
the height of the tree at the end of the 4th cycle = 7


SOLUTION 


#include<stdio.h>
int main()
    {
    int T, N[10],m,i,j;
    scanf("%d",&T);
    for(i=0;i<T;i++){
        scanf("%d",&N[i]);
        m=1;
        if(N[i]!=0){
        for(j=1;j<=N[i];j++) {
            if(j%2!=0)
                m=2*m;
            else
                m=m+1;
        }}
        printf("%d \n",m);
    }
    return 0;
}



10 comments:

  1. Why Play Slots at 55XO ? · Support Android and IOS Anywhere · We Have a Safety Policy · Fun in Game We pick from current popularity · Various games We ... สมัคร superslot

    ReplyDelete
  2. Egypt's Book of Mystery slot game comes in an Egyptian fiction theme. The characters that will come out in each spin are amazing because they have beautiful visuals, good techniques, and play ... ฝากถอนslotxo

    ReplyDelete
  3. Deposit and withdraw with a reliable automated system There are more than 100,000 users per day. Unlimited deposits-withdrawals. Login to play online slots here 55xo ... jili เครดิตฟรี

    ReplyDelete
  4. PGSLOT online slots are really easy to play. With a lot of good offers. Play xo slots here 1slot.co win free credits every day. pg slot ฝาก20รับ100

    ReplyDelete
  5. Pokdeng online, card, bingo, gourds, crabs, fish, live football, football steps, all famous leagues and many more Available 24 hours a day. สล็อต ฝาก ถอน ไม่มี ขั้นต่ำ

    ReplyDelete
  6. Serum Find the right product for you. including hair care products, hair coloring, makeup, foundation, lipstick and skin care treatments anti wrinkle that meets the needs ... ทำสีผม

    ReplyDelete
  7. NFTMetaverseFinance.com is an NFT, Metaverse and Cryptocurrency news agency where you can discover news about NFTs, Metaverse projects, crypto coins, ... NFTMetaverseFinance.com

    ReplyDelete
  8. Make Money Online Fast Free provides free various ways on how to earn money from home, how to work from home, and how to earn extra cash online. makemoneyfromhome

    ReplyDelete
  9. Hi! Welcome to the best MP3 juice search engine. Mp3-juice.ninja-downloader.com is your go to place for anything related to mp3 Juice media. mp3juices

    ReplyDelete
  10. A web application made for people who want to calculate tiktok engagement rate and analyse tiktok profile, video, song, or hashtag. tiktok analytics tools

    ReplyDelete