78. C Program to Convert Decimal number Into octal Number.
How does this program work?
- This Program is used to convert Decimal number into Octal number using C program.
- Decimal number means it is a simple integers 0 to 9.
- octa decimal contains 0 to 7 numbers. So totally they are 8 numbers.
- This below code explains how to convert a decimal integer into octal number.
Here is the code
#include <stdio.h>
int main(void)
{
//program to convert an integer into octal number
//Initialize variables
long num, quotient;
int octalNumber[100], i = 1, j;
printf("Enter the decimal number: \n");
scanf("%ld", &num);
quotient = num;
while (quotient != 0)
{
octalNumber[i++] = quotient % 8;
quotient = quotient / 8;
}
printf("Equivalent octal value of decimal no %d: ", num);
for (j = i - 1; j > 0; j--)
printf("%d", octalNumber[j]);
return 0;
}