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

Command Line Program to Convert Binary to Octal

👁 1,121 Views
💻 Practical Program
📘 Step by Step Learning
Command Line Program to Convert Binary to Octal. This is a very smart program very short and quick method.

Program Code

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

Output

1010

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.