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




Comments

Popular posts from this blog

C Program for SCAN Disk Scheduling Algorithm | C Programming

C program to Find Cartesian Product of Two Sets | C programming

C Program To Check The String Is Valid Identifier Or Not | C Programming