[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

Program Discussion :: Basics

Home > Programs > Basics

338 / 279

Write a c program to convert decimal to binary using command line arguments?

Answer:

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

Asked In :: TCS

Post Your Answer Here:

Language:

Post Your Reply Here:



Language:

Post Your Reply Here: