# C Program to Converter a Decimal to Octal

You are Here:

## Converter a Number from Decimal to Octal

In the following example, we will convert a Decimal Number (100) to Octal Number (144).

Tips: It is recommended to use our online Decimal to Octal calculator for better understanding.

### Example

C Compiler
#include <stdio.h> #include <math.h>; int main() { int num = 23456; int arr, i, answer; const int oct = 8; int value = 1; int j = 0; int count = -1; while(num > value) { count++; value = pow(oct, count); arr[count] = value; } count = count - 1; for(i=count; i>=0; i--) { answer[j] = num / arr[i]; j++; num = num % arr[i]; } printf("Octal number of 23456 (decimal) is "); for(i=0; i<=count; i++) printf("%d", answer[i]); return 0; }

### Output

Octal number of 23456 (decimal) is 55640

## Converter any Given Decimal Number to Octal Number

In the following example, we will convert any given decimal number to an octal number.

### Example

C Compiler
#include <stdio.h> #include <math.h>; int main() { int num, copyNum, arr, i, answer; const int oct = 8; int value = 1; int j = 0; int count = -1; printf("Enter a Decimal Number: "); scanf("%d", &num); copyNum = num; while(copyNum > value) { count++; value = pow(oct, count); arr[count] = value; } count = count - 1; for(i=count; i>=0; i--) { answer[j] = copyNum / arr[i]; j++; copyNum = copyNum % arr[i]; } printf("Octal number of %d (decimal) is ", num); for(i=0; i<=count; i++) printf("%d", answer[i]); return 0; }

### Output

Enter a Decimal Number: 10 Octal number of 10 (decimal) is 12

## Reminder

Hi Developers, we almost covered 98% of String functions and Interview Question on C with examples for quick and easy learning.

We are working to cover every Single Concept in C.