0

Even numbers and odd numbers in c++

How to print even and odd numbers in C++

8th Nov 2022, 8:21 AM
Coder0900
8 Answers
+ 2
#include<iostream> using namespace std; int main() { int n; cin>>n; if(n%2==0) { cout<<"even number"; } else { cout<<"odd number"; } return 0; }
8th Nov 2022, 8:28 AM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
+ 1
Code attempt?
8th Nov 2022, 8:25 AM
Abate Mon'y
Abate Mon'y - avatar
+ 1
Vijesh V learn C++ on Sololearn step by step, btw cin -> input the user int n -> n is a variable and int is a datatype n%2 -> % is a modulas operator and it gives remainder, and n%2 suppose if you input the n = 2, then 2 divide 2 the remainder is 0 so it's even number if,else -> if-else block conditional statements You can learn on Sololearn then you can easily understand why we use these.
8th Nov 2022, 8:48 AM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
+ 1
Thank you for the help Sakshi
8th Nov 2022, 8:52 AM
Coder0900
+ 1
It will be best if you follow the lessons . It will give you an understanding of these concepts and when to use them.
9th Nov 2022, 10:26 AM
Edeh
+ 1
Ok thank you
9th Nov 2022, 12:07 PM
Coder0900
0
I am new to programming. I don't even know the basics, but I got the question of how to print even odd and odd numbers in C++it by typing code as same as others do? Code: int cout (iostream) Input (even numbers and odd numbers; // Numbers = (1,2,3,4,5,6,7,8,9,0); Even numbers int = {2,4,6,8,10} ; Odd numbers = {1,3,5,7,9} ; //
8th Nov 2022, 8:32 AM
Coder0900
0
Thank you Sakshi. But one question: What is cin? What is n? What is n%2? What is return, if , else? Why did you used these?
8th Nov 2022, 8:40 AM
Coder0900