DECIMAL TO BINARY - CPPIOA006

Description:

Write a C++ Program to Find the Binary Value of Decimal Number Using for loop Test Case 1 Input (stdin) 2 Expected Output 10 Test Case 2 Input (stdin) 10 Expected Output 1010

Program :

#include <iostream>
using namespace std;
int main()
{
int n,a[50],i=0,m=0;
  cin>>n;
  while(n>0)
  {
    a[i]=n%2;
    n=n/2;
  i++;
    m++;
  }
  for(i=m-1;i>=0;i--)
    cout<<a[i];
 return 0;
}