0
Even numbers and odd numbers in c++
How to print even and odd numbers in C++
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;
}
+ 1
Code attempt?
+ 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.
+ 1
Thank you for the help Sakshi
+ 1
It will be best if you follow the lessons . It will give you an understanding of these concepts and when to use them.
+ 1
Ok thank you
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} ;
//
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?