logo
  • Home
  • Test & Rank
  • About
  • Training
  • Programming
  • CS
  • IT
  • IS
  • ECE
  • EEE
  • EE
  • Civil
  • Mechanical
  • Chemical
  • Metallurgy
  • Instrumentation
  • Aeronautical
  • Aerospace
  • Biotechnology
  • Mining
  • Marine
  • Agriculture
  • MCA
  • BCA
  • Internship
  • Jobs
  • Contact

Questions & Answers

C Interview Questions
C++ Questions
Linux MCQs
C# Quiz
Java MCQs
JavaScript MCQs
SAN Questions
PHP Questions
Python Quiz

Computer Science Questions

Operating System Quiz
Computer Architecture MCQs
Software Architecture MCQs
Software Engineering MCQs
Artificial Intelligence MCQs
LISP Programming MCQs
Database Management MCQs
Computer Network MCQs
Microprocessor MCQs

C Programming Examples

Simple C Programs
C - Arrays
C - Matrix
C - Strings
C - Bitwise Operations
C - Linked Lists
C - Stacks & Queues
C - Searching & Sorting
C - Trees
C - Strings
C - File Handling
C - Mathematical Functions
C - Puzzles & Games
C Programs - Recursion
C Programs - No Recursion

Java Algorithms

Java - Numerical Problems
Java - Combinatorial Problems
Java - Graph Problems
Java - Hard Graph Problems
Java - Computation Geometry
Java - Sets & Strings
Java - Data-Structures
Java - Collection API Problems

C++ Algorithms

C++ - Numerical Problems
C++ - Combinatorial Problems
C++ - Graph Problems
C++ - Hard Graph Problems
C++ - Computation Geometry
C++ - Sets & Strings
C++ - Data-Structures
C++ - STL Library

C Algorithms

C - Numerical Problems
C - Combinatorial Problems
C - Graph Problems
C - Hard Graph Problems
C - Computation Geometry
C - Sets & Strings
C - Data-Structures

« Prev Page
Next Page »

C program to Convert Decimal to Octal

Posted on February 10, 2013 by staff10

This is a C program to Convert Decimal to Octal.

Problem Description

This program takes a decimal number as input and converts to octal number.

Problem Solution

1. Take a decimal number as input.
2. Divide the input number by 8 and obtain its remainder and quotient. Store the remainder in the array.
3. Repeat the step 2 with the quotient obtained. Do this until the quotient becomes zero.
4. Print the array in the reverse order to get the output.

advertisement
Program/Source Code

Here is source code of the C program to Convert Decimal to Octal. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. /*
  2.  * C program to Convert Decimal to Octal
  3.  */
  4. #include <stdio.h>
  5.  
  6. int main()
  7. {
  8.     long decimalnum, remainder, quotient;
  9.     int octalNumber[100], i = 1, j;
  10.  
  11.     printf("Enter the decimal number: ");
  12.     scanf("%ld", &decimalnum);
  13.     quotient = decimalnum;
  14.     while (quotient != 0)
  15.     {
  16.         octalNumber[i++] = quotient % 8;
  17.         quotient = quotient / 8;
  18.     }
  19.     printf("Equivalent octal value of decimal no %d: ", decimalnum);
  20.     for (j = i - 1; j > 0; j--)
  21.         printf("%d", octalNumber[j]);
  22.     return 0;
  23. }
Program Explanation

1. Take a decimal number as input and store it in the variable decimalnum.
2. Copy the variable decimalnum to the variable quotient.
3. Divide the variable quotient and obtain its remainder and quotient. Store the remainder in the array octalNumber and override the variable quotient with the quotient obtained.
4. Repeat the step 3 until the quotient becomes zero.
5. When it becomes zero, print the array octalNumber in the reverse order to get the output.

advertisement
Runtime Test Cases
Output:
Enter the decimal number: 68
Equivalent octal value of decimal no 68: 104

Sanfoundry Global Education & Learning Series – 1000 C Programs.

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Simple C Programs, go to Simple C Programs. If you wish to look at programming examples on all topics, go to C Programming Examples.
« Prev Page - C Program to Convert Binary to Hexadecimal
» Next Page - C program to Convert Decimal to Hexadecimal

« C Program to Convert Binary to Hexadecimal
C program to Convert Decimal to Hexadecimal »

Deep Dive @ Sanfoundry:

  1. C Programming Examples on File Handling
  2. Java Programming Examples on Data-Structures
  3. C Programming Examples on Arrays
  4. C++ Programming Examples on Data-Structures
  5. C# Programming Examples on Delegates
  6. C Programming Examples using Recursion
  7. C# Programming Examples on Arrays
  8. Java Programming Examples on Mathematical Functions
  9. Simple C Programs
  10. C# Programming Examples on Conversions
Manish Bhojasia
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Facebook | Twitter

Best Careers

Developer Tracks
SAN Developer
Linux Kernel Developer
Linux Driver Developer
Linux Network Developer

Live Training Photos
Mentoring
Software Productivity
GDB Assignment
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel Programming. Our Founder has trained employees of almost all Top Companies in India such as VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium, ST-Micro, Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Mphasis, Tata-Elxsi, Tata VSNL, Mindtree, Cognizant and Startups.

Best Trainings

SAN I - Technology
SAN II - Admin
Linux Fundamentals
Advanced C Training
Linux-C Debugging
System Programming
Network Programming
Linux Threads
Kernel Programming
Kernel Debugging
Linux Device Drivers

Best Reference Books

Computer Science Books
Algorithm & Programming Books
Electronics Engineering Books
Electrical Engineering Books
Chemical Engineering Books
Civil Engineering Books
Mechanical Engineering Books
Industrial Engineering Books
Instrumentation Engg Books
Metallurgical Engineering Books
All Stream Best Books

Questions and Answers

1000 C Questions & Answers
1000 C++ Questions & Answers
1000 C# Questions & Answers
1000 Java Questions & Answers
1000 Linux Questions & Answers
1000 Python Questions
1000 PHP Questions & Answers
1000 Hadoop Questions
Cloud Computing Questions
Computer Science Questions
All Stream Questions & Answers

India Internships

Computer Science Internships
Instrumentation Internships
Electronics Internships
Electrical Internships
Mechanical Internships
Industrial Internships
Systems Internships
Chemical Internships
Civil Internships
IT Internships
All Stream Internships

About Sanfoundry

About Us
Copyright
Terms
Privacy Policy
Jobs
Bangalore Training
Online Training
Developers Track
Mentoring Sessions
Contact Us
Sitemap
© 2011 Sanfoundry. All Rights Reserved.