C++ Program to Covert Octal to Hexadecimal

C++ Program to Covert Octal to Hexadecimal

Write C++ Program to Covert Octal to Hexadecimal

// CPP Program to Covert Octal to Hexadecimal

#include <iostream>
#include <math.h>

using namespace std;

int main()
{
	int n, sum = 0;

	cout << "Enter the Octal Number :--> ";
	cin >> n;

	int i = 0;
	while(n != 0)
	{
		int digit = n % 10;
		sum = sum + (digit * pow(8,i));
		n = n / 10;
		i++;
	}

	cout << "\nThe Decimal Number is :--> " << sum;
	int ans = 0,j = 0;
	while(sum != 0)
	{
		int digit = sum % 16;
		ans = ans + (digit * pow(10, j));
		sum = sum / 16;
		j++;
	}
	cout << "\nThe Hexadecimal Number is :--> " << ans;

	return 0;
}

Output:

Enter the Octal Number :--> 56

The Decimal Number is :--> 46
The Hexadecimal Number is :--> 34