UVA 11185 - Ternary

UVA Sep 01, 2020

Problem PDF

Solution:

#include
int main()
{
    long long i,n,j,b[10000];
    while(scanf("%lld",&n))
    {
        if(n<0)
        break;
        else if(n==0)
        {
            printf("0\n");
        }
        else
        {
            i=0;
            while(n>0)
            {
                b[i]=n%3;
                n=n/3;
                i++;
            }

            i=i-1;
            for(j=i;j>=0;j--)
                printf("%lld",b[j]);

            printf("\n");
        }
    }
    return 0;
}
https://github.com/Shipu/OnlineJudgeProblemSolutionWithCPlusPlus/tree/master/uva/11185/11185.cpp

Tags

Shipu Ahamed

CSPO® | Partly Product, Project Manager and Partly Software Engineer.

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.