Thursday, November 13, 2014

GREATEST & bINARY VALUE OF C++ PROGRAM



C++ program to find greatest number between three numbers

#include
#include
     int main()
{
   int num1,num2,num3;
    cout<<" Enter value for first number";
    cin>>num1;

    cout<<" Enter value for second number";
    cin>>num2;

    cout<<" Enter value for third number";
    cin>>num3;
    if(num1>num2&&num1>num3)
      {
          cout<<" First number is greatest:"<
      }
    else
     if(num2>num1&&num2>num3)
      {
          cout<<" Second number is greatest"<
      }
    else
    {
        cout<<" Third number is greatest"<
    }
return 0;
}

 

Find the binary value of decimal number in C++


#include
#include
     int main()
{
  int n,x,a, c, k;

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

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

  {
     n=n/2;
  }

a=a-2;
  for (c = a; c >= 0; c--)
  {
    k = x >> c;

    if (k & 1)
      cout<<"1";
    else
      cout<<"0";
  }
        return 0;
}




No comments:

Post a Comment