Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

reversing array for conversion to binary number

$
0
0

I'm looking to perform the decimal to binary conversion...how do I reverse the binary code stored in str[i], marked in asterisk so that I get the correct output ??

#include <stdio.h>
#include <string.h>

void main()
{

     int a, b, c, i;
     int str[10];

     printf("Enter an integer of your choice : ");
     scanf("%d", &a);

    b=a;

while (a!=0)
  {
     for (i=0;a>i;i++)
        {
           c=a%2;
           str[i]=c; // ***** the binary value is stored here

           printf("%d", str[i]);
           a=a/2;
           i++;
        }
   }

}

Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>