+ 4

how to write a program in c++ finding the number is even or odd

7th Sep 2017, 4:02 AM
Yash🏁🔘
Yash🏁🔘 - avatar
5 Respuestas
+ 8
cin>>i; if (i%2==0){cout<<"Number is even}; else{cout<<"Number is odd";}
7th Sep 2017, 4:13 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 7
That, or simply std::cout << "Number is " << (i % 2 ? "odd" : "even");
7th Sep 2017, 8:30 AM
Hatsy Rei
Hatsy Rei - avatar
+ 5
thanks friends
7th Sep 2017, 8:36 AM
Yash🏁🔘
Yash🏁🔘 - avatar
+ 1
bool isodd(int x) { return x % 2; } bool iseven(int x) { return !isodd(x); }
7th Sep 2017, 6:12 AM
Testing003