RUN


Convert Decimal To Octal program

A decimal number is taken and converted into its octal equivalent.

Example:

Decimal number: 50

Corresponding octal number: 62 

Algorithm

  1. A decimal number is taken as input.
  2. The number is divided by 8 and the remainders are stored.
  3. The result is printed in reverse order.
  4. Exit.

Code:

include <iostream>
using namespace std;

int main()

{

     long dno, temp;

     int octal[100], i = 1, j;

     cout<<"Enter the decimal number: ";

     cin>>dno;

     temp = dno;

     while (temp != 0)

     {
         octal[i++] = temp % 8;
         temp = temp / 8;
     }

     cout<<"Equivalent octal value of decimal no: ";

     for (j = i - 1; j > 0; j--)

         cout<<octal[j];

     return 0;

}

Report Error/ Suggestion

Related Posts:




CopyRight © 2020

CopyRight © 2020