-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patheven-odd.l
47 lines (38 loc) · 864 Bytes
/
even-odd.l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
%{
/*
1.Request input of an even and an odd number
2.indicate input characteristic : Even/Odd [digit_length]
3.check for input's correctness and print result
*/
#include<stdlib.h>
#include<stdio.h>
int number_1;
int number_2;
%}
number_sequence [0-9]*
%%
{number_sequence}[0|2|4|6|8] {
printf("Even number [%d]",yyleng);
return atoi(yytext);
}
{number_sequence}[1|3|5|7|9] {
printf("Odd number [%d]",yyleng);
return atoi(yytext);
}
%%
int yywrap
{
return 1;
}
int main()
{
printf("\nInput an even number and an odd number\n");
number_1 = yylex();
number_2 = yylex();
int diff = number_1 - number_2;
if(diff%2!=0)
printf("\nYour inputs were checked for correctness, \nResult : Correct\n");
else
printf("\nYour inputs were checked for correctness, \nResult : You do not know how to read\n");
return 1;
}