In this program, you'll learn to convert Ocatl number to Decimal number system. Decimal to binary in C: We can convert any decimal number (base-10 (0 to 9)) into binary number(base-2 (0 or 1)) by c program. Decimal number is a base 10 number, there are total 10 digits between 0 to 9. Any combination of digits is decimal number such as 23, 445, 132, 0, 2 etc. Octal number is a base 8 number contains only 8 digits either 0 through 7. Any combination of digits is octal number such as 116, 33, 133, etc.
#include <stdio.h>
int main()
{
int dec, i, rem, c=1;
int oct = 0;
printf("Enter the Decimal number: ");
scanf("%d", &dec);
while(dec > 0)
{
rem = dec % 8;
oct = oct + rem * c;
dec = dec / 8;
c = c * 10;
}
printf("Octal Equivalent is: %ld", oct);
return 0;
}
Enter the Decimal number: 33
Octal Equivalent is: 41
Enter the Decimal number: 10
Octal Equivalent is: 12