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

C Programming Language Command Line Arguments (Article) Command Line Arguments (Program)

1017

Program:

#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;
    
}

}

Output:

10

1010

Explanation:

Nope

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.