i am trying to convert decimals to binary ..the reason i am using function is becoz i want to include -ve numbers too .......i was sucessfull for the positive but for making it run for -ve numbers to i divided into a new function....but i am not able to figure out when i return a pointer frm a function ...hw to print that out in the main function
here is the code:
#include<iostream>
#include<iomanip>
using namespace std;
int *unsign(int);
int main()
{
int *bins;
int num;
cout<<"enter the number you want to convert:"<<endl;
cin>>num;
bins= unsign(num);
int i=0;
// this is the place where i am stuck
for(int i=0;i<5;i++)
cout<<bins[i];
delete []bins;
bins=0;
return 0;
}
int *unsign(int num)
{
int number;
int *bin;
static int count =0;
number=num;
while (num>1)
{
num=num/2;
count++;
}
count++;
bin= new int[count];
for(int i=0;i<count;i++)
{
bin[(count-1)-i]=number%2;
if ((count-1)-i==0)
{
bin[0]=1;
}
}
return bin;
}