-
Notifications
You must be signed in to change notification settings - Fork 156
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
|
||
|
||
**C++ Implementation** | ||
|
||
``` | ||
#include<bits/stdc++.h> // includes everything | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lose the comment. |
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
} | ||
} | ||
``` |
Uh oh!
There was an error while loading. Please reload this page.