TCS Coding Problem 9

10 comments on “TCS Coding Problem 9”


  • GAURAV

    #include
    #include
    #include

    using namespace std;

    int main()
    { int n;
    vectorv;
    cin>>n;
    int rem=0;
    while(n>8){
    int rem=n%8;
    n/=8;
    v.push_back(rem);
    }
    v.push_back(n);
    reverse(v.begin(),v.end());
    for(auto it:v)
    cout<<it;

    return 0;
    }


  • amit

    #include

    int main()
    {
    int num;
    int arr[100];
    int count=0;
    int i=0;
    scanf(“%d”,&num);
    while(num!=0)
    {
    arr[i]=num%8;
    num=num/8;
    i++;
    }
    for(int j=i-1;j>=0;j–)
    {
    printf(“%d”,arr[j]);
    }

    return 0;
    }


  • Raman

    // Online C compiler to run C program online
    #include

    int main() {
    int n,a[20],rem;
    int count=0,i=0;
    printf(“enter the number :”);
    scanf(“%d”,&n);

    while(n>0){
    rem=n%8;
    a[i]=rem;
    n=n/8;
    i++;
    count++;
    }
    for(i=count-1;i>=0;i–){
    printf(“%d”,a[i]);
    }

    return 0;
    }


  • 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”)