DECIMAL TO BINARY - CPPIOA004

Description:

Can you help your digital design faculty in correcting the assignment on number conversions decimal number to its equivalent binary number. by writing a program to convert a decimal number to its equivalent binary number. Input and Output Format : Input consists of a single integer. Output is the binary equivalent of the decimal input. [Refer sample input and output for formatting specifications. Test Case 1 Input (stdin) 9 Expected Output 1001 Test Case 2 Input (stdin) -9 Expected Output -9 is not a positive integer.

Program :

#include <iostream>

using namespace std;

int main()

{

int n,a[50],i=0;

  cin>>n;

  if(n>=0)

  {

  while(n!=0)

  {

    if(a[i]%2==0)

      cout<<"0";

    else

      cout<<"1";

    n=n/2;

    i++;

  }}

  else

    cout<<n<<" is not a positive integer.";

return 0;

}