Menu

COJ 2196 – Even? Odd?

January 1, 2017 - COJ

If the last digit of a number is divisible by 2 it means that the entire number is also divisible by 2. The rest is easy, input it as a string, take the last char and check.

Language: C++

#include <iostream>
#include <string>
using namespace std;
string s;
int main() 
{
	int i,j,k,t;
	cin>>t;
	for(k=1;k<=t;k++)
	{
		cin>>s;
		if( int(s[s.size()-1]-'0')%2==0)
			cout<<"even"<<endl;
		else
			cout<<"odd"<<endl;
	}
	// your code goes here
	return 0;
}

(42)

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on VK

Author of this post : safrastyan

Leave a Reply

Your email address will not be published. Required fields are marked *