C Program to Convert Octal Number to Decimal and vice-versa

To understand this example, you should have the knowledge of the following C programming topics:


Example 1: Program to Convert Decimal to Octal

Output

Enter a decimal number: 78
78 in decimal = 116 in octal

Example 2: Program to Convert Octal to Decimal

Output

Enter an octal number: 116
116 in octal = 78 in decimal

Note: This program doesn't work if we input non-octal numbers i.e., numbers that contain 8 or 9. For example, 187, 96, 985, etc., are not octal numbers.


Example 3: Check for Octal Number and Convert it to Decimal

Enter an octal number: 96
96 is not an octal number!
Enter an octal number: 25
25 in octal = 21 in decimal