Hi Friends,
I am trying to convert a number to its binary form.
I have done till here
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,arr[20],rem[20],c;
cout<<"enter the number";
cin>>a;
for(int i=a;i>=1;)
{
rem[c]=i%2;
i=i/2;
cout<<rem[c];
}
getch();
}
But I now need to take the palindrome of the array rem[c] to get the answer .
Can anybody help????
First of all, 'c' is uninitialized, and you're not using 'b' and 'arr'
You can make a loop that converts the number to binary (done), using a variable that keeps track of how many numbers are required to display it, then another loop that prints the binary number starting from the last stored number backwards