C Program To Accept The String That Ends With 01
#include <stdio.h>#include <math.h>#include <string.h>int main(){char s[100];int i = 0, q = 0, l;printf("Enter stringover {0,1}:\n");scanf("%s",s);l = strlen(s);for (i = 0; s[i] != '\0'; i++){if (s[i] == '0' && q == 0){if (i == (l - 2))q = 1;elseq = 0;}else if (s[i] == '1' && q == 0)q = 0;else if (s[i] == '1' && q == 1)q = 2;}if (q == 2){printf("Accepted.\n\n");}elseprintf("Rejected.");return 0;}
OUTPUT #1
OUTPUT #2
Related Posts
C Program To Accept The String Having Even Length | C ProgrammingC Program To Accept The String That Ends With 011 | C Programming
C Program To Accept The String Starting With 01 | C Programming
C Program To Accept The String That Ends With 01 | C Programming
C Program To Accept The String Starting With ab And Ending With abb | C Programming
C Program To Accept The String Starting With 01 And Ending With 011 | C Programming
C Program To Check The String Is Valid Identifier Or Not | C Programming
Post A Comment:
0 comments so far,add yours