TCS Coding Problem 9

7 comments on “TCS Coding Problem 9”


  • swapnil

    public class decimalToOctal {

    public static void main(String[] args) {
    // // TODO Auto-generated method stub
    Scanner s= new Scanner(System.in);
    int num =s.nextInt();
    int rem;
    ArrayList res=new ArrayList();
    while(num>0) {
    rem=num%8;
    num=num/8;
    res.add(rem);

    }
    for(int i=res.size()-1;i>=0;i–) {

    System.out.print(res.get(i));

    }
    }
    }


  • Richik

    def octal(a):
    if a==0:
    return 0
    else:
    return (10*octal(a//8)+a%8)
    print(octal(16))


  • The Bong

    public class DecimaltoOctal {
    public static void main(String[] args) {
    System.out.println(decimelToOctal(14));
    }
    static int decimelToOctal(int decimel) {
    //Using STL
    return Integer.parseInt(Integer.toOctalString(decimel));
    }
    }


  • Gopika Gopal

    #include
    int convert(int);
    void main()
    {
    int dnum;
    scanf(“%d”,&dnum);
    printf(“%d”,convert(dnum));
    }
    int convert(int dnum)
    {
    int onum=0,i=1;
    while(dnum!=0)
    {
    onum=onum+(dnum%8)*i;
    dnum=dnum/8;
    i=i*10;
    }
    return onum;
    }


  • Mohd Saif

    x=int(input(“how many times you want to convert a decimal number into equivalent octal number:\n”))
    for i in range(x):
    n=int(input(“enter the decimal number:\n”))
    print(“Its equivalent octal number is:”,oct(n),”starting first two symbol of octal i.e zero and o”)