ma first thread here:::::::

sanchit goyal's Avatar, Join Date: Feb 2010
Newbie Member
this is ma first thread so hoping for +ve repleis..........
first of all i wud like to tell u tht m at the very basic level(actually basic se bhi neeche ata hun mein)
i have made program to convert decimal to binary
in two ways plzz find out ma mistakes in dese two progs:::::::::::

Code:
#include<iostream.h>
#include<conio.h>
#include<process.h>
void dectobin(int ,int );
int main()
{clrscr();
int decimal;
cout<<"enter a decimal integer to convert it to binary :";
cin>>decimal;
cout<<"\nIn Binary is :\n";
dectobin(decimal,2);
cout<<endl;
return 0;
}
void dectobin(int num,int base)
{
if(num>0)
{
dectobin(num/base,base);
cout<<num%base;
}
}
:::::::
:::::::::
::::::
Code:
 
#include<iostream.h>
#include<conio.h>
void dec2bin(int bin[])
{
int n;
for(int i=0;n!=0;i++)
{
bin[i]=n%2;
}
for(int j=i-1;j>=0;j--)
bin[j]=bin[i];
cout<<bin[j]<<" ";
}
getch();
}
void main()
{clrscr();
int x,y[100];
cout<<"enter a number to convert it into binary :";
cin>>x;
cout<<"the binary equivalent is :";
dec2bin(y);
}

Last edited by shabbir; 27Feb2010 at 09:51.. Reason: Code blocks
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
You posted this in introduction forum without code blocks and that too without a title which can make people to see and reply.

Now coming to your query I think if you search you will get what you are looking for,.
0
vivekraj's Avatar, Join Date: Feb 2010
Light Poster
I did small changes in your code.Now the program is working fine.You execute it and revert me if any problem occurs.
Code:
#include<iostream.h>
#define MAXSIZE 100
void dec2bin(int n)
{
    int i,bin[MAXSIZE],t,i1=0;
    for(i=0;n>=1;i++)
    {
        t=n%2;
        n=n/2;
        i1++;
        bin[i]=t;
    }
    for(i=(i1-1);i>=0;i--)
        cout<<bin[i];
    cout<<"\n";
}
main()
{
int x;
cout<<"Enter a number to convert it into binary :";
cin>>x;
cout<<"The Binary Equivalent is :";
dec2bin(x);
}

Last edited by shabbir; 27Feb2010 at 12:41.. Reason: Code blocks
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Quote:
Originally Posted by sanchit goyal View Post
this is ma first thread so hoping for +ve repleis..........
first of all i wud like to tell u tht m at the very basic level(actually basic se bhi neeche ata hun mein)
Stop using txtspk; it makes you sound like a teenage girl. txtspk works and is tolerated when you only have a mobile phone keypad but you have a full keyboard in front of you. Use it. The more you use it the quicker it gets and you will find yourself being able to do 20-30wpm without any training after a while.

Actually I couldn't decode the bit in brackets at all. If you can't be bothered to type your question out in full using proper grammar then I can't be bothered trying to figure out the answer.
hanleyhansen, shabbir likes this