ADS

C Program To Accept The String That Ends With 01 | C Programming

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;
            else
                q = 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");
    }
    else
        printf("Rejected.");
    return 0;
}

OUTPUT #1

C Program To Accept The String That Ends With 01

OUTPUT #2

C Program To Accept The String That Ends With 01

Related Posts

C Program To Accept The String That Ends With 011 | C Programming

C Program To Accept The String Having Even Length | C Programming

C Program To Accept The String Having Length At Least Two | C Programming

C Program To Accept The String Starting With 01 | C Programming

C Program To Accept The String Starting With ab And Ending With abb | C Programming


Post a Comment

0 Comments