Decimal to Binary in C++
RELATED POSTS
- Blogger Comment
- Facebook Comment
Subscribe to:
Post Comments
(
Atom
)
C/C++,java,python c++ keywords, identifiers, data types,variables,modifiers,storage classes,operators,for loop ,while loop,do while loop,if else statement,nested loops,break continue goto statement,functions ,call by value call by reference ,arrays ,strings,pointers,data structures ,classes and objects,inheritance,polymorphism,operator overloading,function overloading,data abstraction,data encapsulation,dynamic memory allocation for array and objects,function templates,class templates,
Decimal to Binary in C++
Integer N
Corresponding Binary number (long)
0 <= N <= 10^5
12
1100
7
111
C++ Code:
#include<iostream>
using namespace std;
int main() {
long int n,binary=0,i=1,rem;
cin>>n;
while(n!=0)
{
rem=n%2;
binary=binary+(rem*i);
n=n/2;
i*=10;
}
cout<<binary;
}
0 comments:
Post a Comment