Home› C Programming Language for Problem Solving› / Programs / Command Line Program to Convert Decimal to Octal
🚀 Programming Example

Command Line Program to Convert Decimal to Octal

548 Views
Beginner
Code Snippet
Command Line Program to Convert Decimal to Octal. This is very smart short and quick program.

💻 Program Code

#include<stdio.h>
int main(int argc,char *argv[])
{
	int n,s=0,b=1,r;
	n=atoi(argv[1]);
	int c=n;
	while(c>0)
	{
		r=c%8;
		s=s+r*b;
		c=c/8;
		b=b*10;
	}
	printf("%d",s);
	getch();
}

🖥 Program Output

                                10

12
                            

📘 Explanation

Nope
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.