Thursday, 25 January 2018

DECIMAL-TO-BINARY CPP PROGRAMMING

Output:
Enter Decimal Value:4

Binary value =100

Enter Decimal Value:15
Binary value =1111

Code for Decimal to Binary:

#include <iostream>
#include <cmath>
using namespace std;
 int main()
{
int a,b=0,c=1;
long bin=0;
cout<<"Enter Decimal Value:";
cin>>a;
while(a>0)
{
    b=a%2;
    a/=2;
    bin=bin+(b*c);
    c=c*10;
}
cout<<"Binary value ="<<bin;

}

No comments:

Post a Comment

we are hear to discuss your queries ,so please feel free to ask any of your queries.

Wikipedia

Search results