Learn about C program to convert decimal to octal using while loop in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
C program to convert decimal to octal using while loop
Program:
#include<stdio.h>
#include<math.h>
int main()
{
int dec, oct=0, rem, i=0;
printf("Enter Decimal Number: ");
scanf("%d",&dec);
while(dec!=0)
{
rem = dec%8;
oct += (rem * pow(10,i));
dec /= 8;
i++;
}
printf("Octal value= %d",oct);
return 0;
}
Output:
Enter Decimal Number: 60
Octal value= 74
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Codes :
C program to convert binary to decimal using function
C program to convert binary to decimal