Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- enum { EVEN, ODD, ERROR } state=EVEN;
- int c;
- printf("Enter stream of 0 and 1 characters. End=CTRL+Z\n");
- while ((c=getchar())!=EOF) {
- if (c=='\n') continue;
- switch (state) {
- case EVEN:
- if (c=='1') {
- state=ODD;
- puts("ODD");
- } else if (c=='0') {
- puts("EVEN");
- } else {
- puts("ERROR");
- state=ERROR;
- return 0;
- }
- break;
- case ODD:
- if (c=='1') {
- state=EVEN;
- puts("EVEN");
- } else if (c=='0') {
- puts("ODD");
- } else {
- puts("ERROR");
- state=ERROR;
- return 0;
- }
- break;
- case ERROR:
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement