Site icon T4Tutorials.com

C++ Program to convert Octal to decimal number using while loop.

C++ Program to convert Octal to decimal number using while loop.

Flowchart to convert Octal to decimal number using while loop in C++

C++ Octal to decimal number using while loop

C++ Program to convert Octal to decimal number using while loop

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    int num, temp, rem, oct = 0, i = 0;
    cout << "Enter an octal number : ";
    cin >> num;
    temp = num;
    while(temp != 0)
    {
        rem = temp % 10;
        oct += rem * pow(8, i++);
        temp = temp / 10;
    }
    cout << "\nDecimal equivalent of " << num << " is : " << oct;
    return 0;
}

Output

Enter an octal number :

7

Decimal equivalent of 7 is 7.

Let’s see the declarations flow table of the program.

VARIABLE DECLARATION

(LINE NO)

INITILIZATION

(LINE NO)

USE

(LINE NO)

NUM 6 12,8 16,
TEMP 6,10 14,9 12,14
REM 6 12 13,
OCT 6 6,13 16
i 6 6,13

 

13

 YouTube video player

Exit mobile version