Skip to content

Added Tutorial for Even Odd 1 #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Dimik/even-odd-1/en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Even Odd 1

## Hint: You just need to handle last bit

### Solution
* for each test case take the number as a string
* Check the last character of the string
* make it integer
* If its divisible by 2
* its a even number so print 'even'
* if its not divisible by 2
* its a odd number so print 'odd'
Comment on lines +6 to +12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lose the list and summarize it in a few sentences. (You shouldn't need much)
Additionally, you don't need to go all the way to taking the input as a string and checking the last character and all that.
The intended and easier approach would be to divide the number by 2 and checking the remainder. If the remainder is zero, then the number is even; otherwise, odd.



**C++ Implementation**

```
#include<bits/stdc++.h> // includes everything
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lose the comment. bits/stdc++.h doesn't necessarily include everything.

using namespace std;
int main()
{
int t;
cin>>t;
while(t--) // taking input unless test case ends
{
string s;
cin>>s;
int t=s[s.size()-1]-'0'; // last digit of the string
if(t%2==0)
Comment on lines +26 to +29
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change approach. As I mentioned earlier, this is not the simplest of ways.

{
cout<<"even"<<endl;
}
else
{
cout<<"odd"<<endl;
}
}
}
```