Check given number is even or odd using if else statement
#include<iostream> #include<conio.h> using namespace std; int main() { int n; //Declaration of variable cout<<"Enter a number:-"; cin>>n; if(n%2==0) cout<<n<<" is even no."; else cout<<n<<" is odd no."; getch(); }
Check given number is even or odd using Conditional operator
#include<iostream> #include<conio.h> using namespace std; int main() { int n; //Declaration of variable cout<<"Enter a number:-"; cin>>n; n%2==0?cout<<n<<" is even no.":cout<<n<<" is odd no."; getch(); }
Check given number is even or odd using Switch case statement
#include<iostream> #include<conio.h> using namespace std; int main() { int n; //Declaration of variable cout<<"Enter a number:-"; cin>>n; switch(n%2) { case 0:cout<<n<<" is even no."; break; case 1:cout<<n<<" is odd no."; break; } getch(); }
Related programs in C++
0 Comments