13 C program to Convert Decimal to Octal
Posted by Superadmin on December 22 2015 03:14:29
This C Program Converts the given Decimal to Octal. Octal is a numbering system that uses eight digits, 0 to 7, arranged in a series of columns to represent all numerical quantities. Each column or place value has a weighted value of 1, 8, 64, 512, and so on ranging from right to left. Decimal is a term that describes the base-10 number system commonly used by lay people in the developed world.
Here is source code of the C program to Convert Decimal to Octal. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

/*
* C program to Convert Decimal to Octal
*/
#include

int main()
{
long decimalnum, remainder, quotient;
int octalNumber[100], i = 1, j;

printf("Enter the decimal number: ");
scanf("%ld", &decimalnum);
quotient = decimalnum;
while (quotient != 0)
{
octalNumber[i++] = quotient % 8;
quotient = quotient / 8;
}
printf("Equivalent octal value of decimal no %d: ", decimalnum);
for (j = i - 1; j > 0; j--)
printf("%d", octalNumber[j]);
return 0;
}

Output:
$ cc pgm11.c
$ a.out
Enter the decimal number: 68
Equivalent octal value of decimal no 68: 104