# Program for Octal to Decimal Number

## Octal to Decimal Number

We will write a C program to display the conversion of octal number to decimal number and the number will be entered by the user. This will help to understand the basic structure of programming. In this program , we will display the coversion of octal number to decimal number easily by using proper syntax and algorithms.

## Working of Program :

In the program, we will require some numbers from the user to display the conversion of octal number to decimal number.

### Important Note :

• If the number is expressed by base 8 numeral system then that number is octal number.
• If the number is expressed by base 10 numeral system then that number is decimal number.

### Syntax for while() loop:

```while(condition)
{
// Statements
// Increment / Decrement
}
```

### Problem 1

Write a program to convert the octal number into decimal number using while loop.

• Firstly, we have to enter the number.
• Then print the number.

### Code

Run
```#include<stdio.h>
#include<math.h>
int convertDecimalToOctal (int decimalNumber);
int main ()
{
int decimalNumber;
printf ("Enter a decimal number = ");
scanf ("%d", &decimalNumber);
printf ("%d in decimal number = %d in octal number", decimalNumber,
convertDecimalToOctal (decimalNumber));
return 0;
}
int convertDecimalToOctal (int decimalNumber)
{
int octalNumber = 0, i = 1;

while (decimalNumber != 0)
{
octalNumber += (decimalNumber % 8) * i;
decimalNumber /= 8;
i *= 10;
}
return octalNumber;
}
```

### Output

```Enter a decimal number = 67
67 in decimal number = 103 in octal number
```
```Problem 2
```

Write a program to convert the octal number into decimal number using function.

• Firstly, we have to enter the number.
• Then print the number.

### Code

Run
```#include<stdio.h>
#include<math.h>
long long convertOctalToDecimal (int octalNumber);
int main ()
{
int octalNumber;
printf ("Enter an octal number = ");
scanf ("%d", &octalNumber);
printf ("%d in octal number = %lld in decimal number", octalNumber,
convertOctalToDecimal (octalNumber));
return 0;
}
long long convertOctalToDecimal (int octalNumber)
{
int decimalNumber = 0, i = 0;
while (octalNumber != 0)
{
decimalNumber += (octalNumber % 10) * pow (8, i);
++i;
octalNumber /= 10;
}
i = 1;
return decimalNumber;
}
```

### Output

```Enter an octal number = 89
89 in octal number = 73 in decimal number
```

### Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

## Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others