C Online Compiler
Example: Decimal to Octal Conversion in C Programming
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Decimal to Octal Conversion in C Programming #include <stdio.h> void convertDecimalToOctal(int x) { int octalNum[100]; int i = 0; while (x != 0) { // this will store remainder in octal array octalNum[i] = x % 8; x = x / 8; i++; } // This will print octal number array in reverse order printf("The octal number is: "); for (int j = i - 1; j >= 0; j--) printf("%d", octalNum[j]); printf("\n"); } int main() { int x; // This will store the any decimal number printf("-----Enter any decimal number to make conversion-----\n"); scanf("%d", &x); // This will convert decimal to octal convertDecimalToOctal(x); return 0; }
37
Output
Clear
ADVERTISEMENTS