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