Site icon DataFlair

C++ Program to Convert Decimal to Octal

Master C++ with Real-time Projects and Kickstart Your Career Start Now!!

Program 1

// Decimal to Octal Conversion
#include<iostream>
#define clrscr() system("cls")
using namespace std;

int main()
{
      int d,oct[100],i,r;
      clrscr();
      cout<<"\nEnter decimal number";
      cin>>d;
      i=0;
      //Conversion of decimal to octal
      while(d!=0)
      {
           r=d%8;
          oct[i]=r;
          d=d/8; 
          i++;
      }
      i--;
      cout<<"\n\n Octal Number: ";
      while(i>=0)
      {
        cout<<oct[i];
        i--;
      }
      return 0;
}

 

Exit mobile version