Example & Tutorial understanding programming in easy ways.

Write a program to convert the decimal number to its octal equivalent

Decimal number:
Consists of 10 eleemnts
range : 0 to 9

Octal numnber :
Consists of 8 elements
range : 0 to 7

Decimal to octal conversion:

Example-
Decimal number is 7
Octal number is 7

Decimal number is 41
Octal number is 15

program-

#include< stdio.h>
int main() {
int n,num=0;
printf("Enter decimal number");
scanf("%d",&n);
while(n)
{
num=num*10+n%8;
n=n/8;
}
printf("It's Octal is %d",num);
}


output-

Enter decimal number
10
It's Octal is 21

Enter decimal number
41
It's Octal is 15

-In this program, we take an input of decimal number and find its octal equivalent.




Read More →