➽ Program:-
#include<iostream>
#include<math.h>
using namespace std;
long OctalToBinary(int octal_number)
{
int decimal_number = 0, i = 0;
long binary_number = 0;
while(octal_number != 0)
{
decimal_number += (octal_number % 10) * pow(8,i);
i++;
octal_number = octal_number / 10;
}
i = 1;
while(decimal_number != 0)
{
binary_number += (decimal_number % 2) * i;
decimal_number = decimal_number / 2;
i = i * 10;
}
return binary_number;
}
int main()
{
int octal_number;
cout << "Enter an Octal Number: ";
cin >> octal_number;
cout << "Binary number is " <<
OctalToBinary(octal_number);
return 0;
}
➽ Output:-
0 Comments
Please do not enter any spam link in the comment section.