Lex program to check whether input number is odd or even
Lex is a computer program that generates lexical analyzers. Lex reads an input stream specifying the lexical analyzer and outputs source code implementing the lexer in the C programming language.
The commands for executing the lex program are:
lex abc.l (abc is the file name) gcc lex.yy.c -ll ./a.out
Let’s see lex program to check whether input number is odd or even.
Examples:
Input : 22 Output : Input Number is Even Input : 53 Output : Input Number is odd
Below is the implementation:
/% Lex Program to check whether - input number is odd or even. %/ % { int i; % } %% [0-9]+ {i = atoi(yytext); if(i%2==0) printf("Input Number is Even"); else printf("Input Number is Odd"); }; %% int main() { yylex(); return 1; } |
chevron_right
filter_none
Output:

Recommended Posts:
- Lex program to check whether the input is digit or not
- Lex program to check whether given number is armstrong number or not
- Lex program to check whether a given number is even or odd
- C Program to check Armstrong Number
- C Program to Check Whether a Number is Prime or not
- Lex Program to check whether a number is Prime or Not
- C++ Program to check Prime Number
- C program to Check Whether a Number is Positive or Negative or Zero
- Program to check if a number belongs to a particular base or not
- Lex program to check valid Mobile Number
- C Program to Check if all digits of a number divide it
- C/C++ Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- Program to find out the data type of user input
- Lex program to take input from file and remove multiple spaces, lines and tabs
- Lex Program to print the total characters, white spaces, tabs in the given input file
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.



