Find the binary value of decimal number in C++

Find the binary value of decimal number in C++
Di Posting Oleh : Simple Learning
Kategori : C++ decimal to binary. Decimal to binary conversion sample code without using arrays

 C++ Program to Find the Binary Value of Decimal Number Using for loop
C++ Code:


  1. #include<iostream>
  2. #include <stdio.h>
  3. using namespace std;

  4. int main()
  5. {
  6.   int n,x,a, c, k;

  7.   cout<<"Enter an integer in decimal number system";
  8.   cin>>x;
  9.   n=x;
  10.   cout<<"Binary Value OF Given Number Is: ";

  11.  for( a=1;n!=0;a++)

  12.   {
  13.      n=n/2;

  14.   }

  15. a=a-2;
  16.   for (c = a; c >= 0; c--)
  17.   {
  18.     k = x >> c;

  19.     if (k & 1)
  20.       cout<<"1";
  21.     else
  22.       cout<<"0";
  23.   }



  24.   return 0;
  25. }
Sample Output:
C++ program to Decimal to Binary Conversion Sample code
Decimal to Binary Conversion Sample output


Image view of Code:
Decimal to Binary Conversion cplusplus code
Decimal to Binary Conversion C++ program code

See Another Example Here
C++ Program to Convert binary number into decimal number

0 Response to "Find the binary value of decimal number in C++"

Post a Comment