Decimal to Octal Conversion in C Programming
ADVERTISEMENTS
Decimal to octal conversion in c programming. In this program, you will learn how to find the decimal to octal conversion in c programming using while loop.
Source Code
// 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;
}
Output
-----Enter any decimal number to make conversion-----
37
The octal number is: 45