In this post, we will write a C++ program to convert the decimal number into a binary number. the first user will enter a number and then the program will print the binary value of that number.

C++ program to convert the decimal number into binary number


C++ program to convert the decimal number into binary number

#include<iostream>
#include<conio.h>

int main()
{
    system("cls");
    int a[50],i,n,r;

    i=0;

    std::cout<<"Enter any number = ";
    std::cin>>n;

    while(n>=1)
    {
        r = n%2;
        n = n-r;
        n = n/2;
        a[i] = r;
        i++;
    }
    i--;

    while(i>=0)
    {
        std::cout<<a[i];
        i--;
    }

    getch();
    return 0;
}



Output

Enter any number = 65
1000001