C++ Problem Help code pls ^^?

Enter a number and determine if the number is odd or even.( Do not use the modulus (%) operator.)

C++ code is needed

Update:

Could you pls use Loop

U can use any type from the list:

1. For Loop

2. Do While

3.While

Comments

  • The binary AND operator version.

    int main(){

    int x;

    cout<<"x=";cin>>x;

    if ((x & 1) == 0) {

    cout<<"even"<<endl;

    }

    if ((x & 1) != 0) {

    cout<<"odd"<<endl;

    }

    }

    Further reading :

    http://bytes.com/groups/cpp/558006-number-odd

  • #comprise iostream using namespace std; int considerable() { int number_of_items; int heating_time; drift recommended_heating_time; on the same time as (a million) { gadget("cls"); recommended_heating_time=0; cout << "nEnter the form of things : "; cin >> number_of_items; cout << "nEnter the single-merchandise heating time: "; cin >> heating_time; if( number_of_items >3) { cout << "nHeating better than 3 products at as quickly as isn't reported. "; } if( number_of_items==3) { recommended_heating_time=heating_time*2; cout << "recommended_heating_time=" << recommended_heating_time; } if( number_of_items==2) { recommended_heating_time=heating_time+he... cout << "recommended_heating_time=" << recommended_heating_time; } if( number_of_items==a million) { recommended_heating_time=heating_time; cout << "recommended_heating_time=" << recommended_heating_time; } cout << endl << endl; gadget("pause"); } }

  • include<iostream.h>

    class OddEven

    {

    int n;

    public

    void odd_even(int);

    };

    void odd_even (int n)

    {

    if (!(n & (n -1))

    cout<<"number is odd";

    else

    cout<<"number is even";

    }

    void main()

    {

    cout<<"Enter Number"

    int x;

    cin>>x

    OddEven ab;

    ab.odd_even(x);

    getch();

    }

Sign In or Register to comment.