# C program to convert decimal number to octal number

list of programs below: C program to convert decimal number to octal number using functions, C program to convert decimal number to octal number without functions

Octal number is a number represented using 8 symbols which are 0 – 7 numbers.
Procedure:Divide the decimal  number with 8 at each step and take remainders.

eg To convert decimal number 10 to Octal

8  | 10
8   | 1 – 2
| 0 – 1

Now combine all remainders serially from down to up  i.e 12 This is Octal number of  10 (decimal )

## Conversion of decimal number to octal program logic:

Enter decimal number n, divide n by 16 ( since Octal ) and save remainder in array and quotient in n repeat until n is greater than zero

write a C program for converting decimal number to octal number using functions

write C a program for converting decimal number to octal number using functions

#include <stdio.h>
void main()
{
int n;
printf(“\n c program for converting decimal number to octal “);
printf(“\n Enter decimal number: \n “;
scanf(“%d”,&n);
Convert_DecimalTo_Octal(n);
getch();
}
// function to convert decimal to octal
void Convert_DecimalTo_Octal(int number)

{
i=0,b;
while ( number>0)
{
b[i]= number%8;
number= number/8;
i++;
}
printf(“\n octal is: “);
while(i>0)
{
printf(b[i]);
i–;
}
}

#### OUTPUT:

c program for converting decimal number to octal
Enter decimal number:
12
octal  is: 14

## write a C program to convert decimal number to octal number without functions

write a c  program to convert decimal number to octal number without functions

#include <stdio.h>
void main()
{
int i=0,n,b;
printf(“\n OUTPUT: c program to convert decimal number to octal number without functions “);
printf(“\nEnter decimal number: “;
scanf(“%d”,&n);
while (n>0)
{
b[i]=n%8;
n=n/8;
i++; }
printf(“\n octal is: “);
while(i>0)
{
printf(b[i]);
i–;
}
}

#### OUTPUT:

OUTPUT: c program to convert decimal number to octal number without functions
Enter decimal number:
10
Octal is: 12