Thursday, 27 August 2020

Viral Advertising Hacker Rank solution in C

 #include<stdio.h>

#include<math.h>
int main()
{
    int n;
    scanf("%d",&n);
    int liked=2,ans=2,shared;
    for(int i=2;i<=n;i++)
    {
        shared = liked *3;
        liked = floor(shared/2.0);
        ans=ans+liked;
    }
    printf("%d",ans);
}

No comments:

Post a Comment