BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

C Program to Convert Decimal to Octal Number

Last Updated: September 25, 2017 by Chaitanya Singh | Filed Under: C Programs

This program converts the input decimal number to an octal number.

Example: Program to convert decimal to octal

In this program, we have created a user defined function decimalToOctal() for decimal to octal conversion. The program takes the decimal number(entered by user) as input and converts it into an octal number using the function. To understand this program, you should be familiar with the following C programming concepts:

  1. C Programming User defined functions
  2. while loop in C programming
#include <stdio.h>
#include <math.h>
/* This function converts the decimal number "decimalnum"
 * to the equivalent octal number
 */
int decimalToOctal(int decimalnum)
{
    int octalnum = 0, temp = 1;

    while (decimalnum != 0)
    {
    	octalnum = octalnum + (decimalnum % 8) * temp;
    	decimalnum = decimalnum / 8;
        temp = temp * 10;
    }

    return octalnum;
}
int main()
{
    int decimalnum;

    printf("Enter a Decimal Number: ");
    scanf("%d", &decimalnum);

    printf("Equivalent Octal Number: %d", decimalToOctal(decimalnum));

    return 0;
}

Output:

Enter a Decimal Number: 436
Equivalent Octal Number: 664

Check out these related C Programs:

  1. C Program to convert Octal to Decimal
  2. C Program to convert Octal to Binary
  3. C Program to convert Binary to Octal
  4. C Program to convert Binary to Decimal
  5. C Program to convert uppercase string to lowercase string

Top Related Articles:

  1. C Program to Convert Binary to Octal Number System
  2. C Program to find the Average of two numbers
  3. C Program to Convert Octal Number to Binary Number
  4. C Program to Convert Octal Number to Decimal Number
  5. C Program to check whether a given integer is positive or negative

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap