Decimal to Octal

C Programming

C Programming Examples

#include<stdio.h>

int main() {
	int decimal, octal = 0, i = 1;
	printf("Welcome to Decimal to Octal converter\n");
	printf("Enter a decimal number:\n");
	scanf("%d",&decimal);
	while(decimal != 0) {
		octal += (decimal % 8) *i;
		i *= 10;
		decimal /= 8;
	}
	printf("Octal value is: %d\n",octal);
	return 0;
}


          /****** Output ******/
          

Welcome to Decimal to Octal converter

Enter a decimal number:

8

Octal value is: 10

Learn more about Decimal and Octal