Lex program to check whether a given number is even or odd

Given a number n, the task is to check whether the given n is even or odd using Lex program.


Input : 10 
Output : Even

Input : 5
Output : Odd

Prerequisite: FLEX (Fast Lexical Analyzer Generator)

An even number is an integer which is “evenly divisible” by 2. This means that if the integer is divided by 2, it yields no remainder or 0 as remainder. Similarly, an Odd number is an integer which is not “evenly divisible” by 2 and will leaves 1 as remainder.

Below is the implementation of above approach:





/*Lex program to take check whether
the given number is even or odd */
int i;
[0-9]+     {i=atoi(yytext);
int yywrap(){}
/* Driver code */
int main()
    return 0;



Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.