C Program to Convert Octal to Decimal

Write C Program to Convert Octal to Decimal

// Write C Program to convert Octal to Decimal

#include <stdio.h>
#include <math.h>

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

	printf("Enter the Octal Number :--> ");
	scanf("%d", &n);

	int i = 0;
	while(n != 0)
	{
		int digit = n % 10;
		ans = ans + (digit* pow(8, i));
		n =  n / 10;
		i++;
	}
	printf("The Decimal Number is :--> %d",ans);
	return 0;
}

Output:

Enter the Octal Number :--> 456
The Decimal Number is :--> 302

≪ Previous | Next ≫