Decimal to Octal

    0

    1

    Giovanny Gongora

    Codiga's C++ Recipes

    Convert decimal number to octal

    #include <iostream>
    #include <cmath>
    
    using namespace std;
    int decimalToOctal(int decimalNumber);
    // Function to convert decimal number to octal
    int decimalToOctal(int decimalNumber)
    {
      int rem, i = 1, octalNumber = 0;
      while (decimalNumber != 0)
      {
        rem = decimalNumber % 8;
        decimalNumber /= 8;
        octalNumber += rem * i;
        i *= 10;
      }
      return octalNumber;
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.