In this tutorial you will learn about the C Program to Convert Decimal to Octal and its application with practical example.
C Program to Convert Decimal to Octal
In this tutorial, we will learn to create a C program that will Convert Decimal to Octal in C programming.
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- While loop in C programming.
Program to Convert Octal to Decimal:-
As we all know the c is a very powerful language. With the help of c programming language, we can make many programs. We cal perform many input-output operations using c programming. In today’s tutorial, we take the input in Decimal from the user and convert it into Octal. With the help of c programming, we can perform many conversion operations.
With the help of this program, we can Convert Decimal to Octal.
1. Declare the variables for the program.
2. Takeing the input number from the user in binary for the program.
3. Passing that input to the string function.
4. Pass that number to a for loop for convertion.
4. Print the Result.
5. End the program.
Program to Convert Decimal to Octal:-
/* C Program to Convert Decimal to Octal */
/* creating a user defined function to convert the decimal number to the octal number */
int convertDecimalToOctal(int decimalNumber);
/* declaring the variable for the program */
/* taking input from the user in decimal number */
printf("Enter a decimal number: ");
/* Printing the output number coverted to octal in the program */
printf("%d in decimal = %d in octal", decimalNumber, convertDecimalToOctal(decimalNumber));
/* The body of the function for convertion */
int convertDecimalToOctal(int decimalNumber)
int octalNumber = 0, i = 1;
while (decimalNumber != 0)
octalNumber += (decimalNumber % 8) * i;
decimalNumber /= 8;
i *= 10;
In the above program, we have first initialized the required variable.
- decimalNumber = in will hold the integer value for the input.
Taking the input.