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




Share To:

Arogya Thapa Magar

Post A Comment:

0 comments so far,add yours