C Program to Convert Decimal Number into Octal



The octal numeral system is the base-8 number system, and uses the digits 0 to 7.



  1. //C program to convert decimal to octal
  2. #include <stdio.h>
  3. int main()
  4. {
  5. long decinum, remainder, quotient;
  6. int octnum[100], i = 1, j;
  7. printf("Enter the decimal number: ");
  8. scanf("%ld", &decinum);
  9. quotient = decinum;
  10. while (quotient != 0)
  11. {
  12. octnum[i++] = quotient % 8;
  13. quotient = quotient / 8;
  14. }
  15. printf("Equivalent octal value of decimal no %d: ", decinum);
  16. for (j = i - 1; j > 0; j--)
  17. printf("%d", octnum[j]);
  18. return 0;
  19. }

Output


Output!