Home / Programs / Command Line Program to Convert Decimal to Octal
Programming Example

Command Line Program to Convert Decimal to Octal

👁 523 Views
💻 Practical Program
📘 Step by Step Learning
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();
}

Output

10

12

Explanation

Nope

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.