i want to write a programe that convert decimal to binary i write two codes first without using function and second is using function,my first code is working properly but second code is not given the desire result. my both codes are here below
#include<iostream.h>
main()
{
int i=0,n,j,b[100];
cout<<"Enter the decimal number";
cin>>n;
while(n>0)
{
b[i]=n%2;
n=n/2;
i++;
}
cout<<" binary is";
j=i-1;
for(i=j;j>=0;j--)
{
cout<<b[j];
}
}
and other code that is not working properly is here
#include<iostream.h>
int bin(int b[]);
main()
{
int n,bina[100];
cout<<"Enter the decimal number";
cin>>n;
bin(bina);
}
int bin(int b[])
{
int i=0;
int num,j;
while(num>0)
{
b[i]=num%2;
num=num/2;
i++;
}
j=i-1;
for(i=j;j>=0;j--)
{
cout<<b[j];
}
}
can any one tells me that what is wrong with second code. thanks in advance
regards,
#include <iostream> // always use <iostream> instead of <iostream.h>
usingnamespace std;
int bin(int b[], int num);// num is the decimal number
int main()
{
int n,bina[100];
cout<<"Enter the decimal number ";
cin>>n;
bin(bina,n);
}
int bin(int b[], int num)
{
int i=0;
int j=0;
while(num>0)
{
b[i]=num%2;
num=num/2;
i++;
}
j=i-1;
for(i=j; j>=0; j--)
{
cout<<b[j];
}
}
hi,
thanks friend its working
but if i use iostream instead of iostream.h my compiler not compile its ok thanks for ur help
just tell me the concept in detail these lines
int bin(int b[], int num);//
bin(bina,n);
int bin(int b[], int num)
waiting for reply
regards,