Sunday, August 13, 2017

decimel to ternary

Sajib's Blog

DECIMEL TO TERNARY




#include<bits/stdc++.h>
using namespace std;
void bse(int n)
{
    if(n==0)return ;

    bse(n/3);
    printf("%d",n%3);
}
int main()
{
    int num;
    while(scanf("%d",&num)==1 && num>=0)
    {
        if(num==0)
        {
            printf("0\n");
            continue;
        }
        bse(num);
        printf("\n");
    }


}

Share:

0 comments: