Example
Input
Input decimal: 22
Output
Octal number: 26
Algorithm to convert decimal to octal
Algorithm Decimal to Octal conversion
begin:
read(decimal);
octal ← 0; place ← 1; rem ← 0;
While (decimal > 0) do
begin:
rem ← decimal % 8;
octal ← (rem * place) + octal;
place ← place * 10;
decimal ← decimal / 8;
end;
print('Octal number' octal);
end;
/**
* C program to convert from Decimal to Octal number system
*/
#include <stdio.h>
int main()
{
long long decimal, tempDecimal, octal;
int i, rem, place = 1;
octal = 0;
/* Input decimal number from user */
printf("Enter any decimal number: ");
scanf("%lld", &decimal);
tempDecimal = decimal;
/* Decimal to octal conversion */
while(tempDecimal > 0)
{
rem = tempDecimal % 8;
octal = (rem * place) + octal;
tempDecimal /= 8;
place *= 10;
}
printf("\nDecimal number = %lld\n", decimal);
printf("Octal number = %lld", octal);
return 0;
}
/*
Output :
Enter any decimal number: 20
Decimal number = 20
Octal number = 24
*/

Comment on “C program to convert Decimal to Octal number system”