ma first thread here:::::::

Discussion in 'C++' started by sanchit goyal, Feb 26, 2010.

  1. sanchit goyal

    sanchit goyal New Member

    Joined:
    Feb 26, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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:happy::happy::happy::happy::happy::happy:)
    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 a moderator: Feb 27, 2010
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    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,.
     
  3. vivekraj

    vivekraj New Member

    Joined:
    Feb 23, 2010
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    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 a moderator: Feb 27, 2010
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice