Skip to content

Adding a tutorial for Dimik-Even Odd 2 #433

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 4 commits 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
37 changes: 37 additions & 0 deletions dimik-even-odd-2/en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Dimik - Even Odd 2

In this problem, you will be given `T` testcases.Each line of the testcase consist of an integer `n` which can be a number consisting of maximum 100 digits.We have to determine whether `n` is odd or even.

## 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'

### C++
```cpp
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
for (int k = 1; k <= t; k++)
{
string s;
cin >> s;
string tmp = "";
tmp += s[s.size() - 1];
int val = stoi(tmp);
if (val % 2)
cout << "odd" << endl;
else
cout << "even" << endl;
}
}
```