Home / Programs / Using Command Line Arguments Program to Convert a Decimal to Binary Number
🚀 Programming Example

Using Command Line Arguments Program to Convert a Decimal to Binary Number

👁 1,105 Views
💻 Practical Program
📘 Step Learning
Convert a Decimal to Binary Number Using Command-Line Arguments Program to

💻 Program Code

#include<stdio.h>
#include<stdlib.h>
int main (int argc, char *argv[]) 
{
  
    if (argc == 1)
    {
    printf ("No Arguments ");
    return 0;
    }
    else
    {
      
        int n;
        n = atoi (argv[1]);
        int binaryN[64];
        int i = 0;
        int j;
      
      while (n > 0)
	    {
	  
        //storing in binary array remainder of number
	    binaryN[i] = n % 2;
	    n = n / 2;
	    i++;
	    }
     
     //printing reverse array
	    while (i)
		{
            printf ("%d", binaryN[--i]);
	
        }
      
 
return 0;
    
}

}

                        

🖥 Program Output

10

1010
                            

📘 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.