Tuesday, December 11, 2018

string belongs to the given grammar or not

C Program for implementation of  language given below
E-> TE’
 E’-> +TE’ | epsilon
T-> FT’
T’-> *FT’  | epsilon
 F-> (E) | i







#include<stdio.h> #include<conio.h> #include<string.h> #include<process.h> void e(); void e1(); void t(); void t1(); void f(); int ip=0; static char s[10]; void main() { char k; int i; ip=0; clrscr(); printf("enter the string:\n "); scanf("%s",s); printf("the string is : %s\n",s); e(); if(s[ip]=='$') printf("String is accepted "); getch(); } void e() { t(); e1(); return; } void t() { f(); t1(); // return; } void e1() { if(s[ip]=='+') { ip++; t(); e1(); } return; } void t1() { if(s[ip]=='*') { ip++; f(); t1(); } return; } void f() { if(s[ip]=='(') { ip++; e(); if(s[ip]==')') ip++; else printf("error closed paranthesis expected"); } else if(s[ip]=='i') ip++; else printf("id expected "); return; }

Thursday, December 6, 2018

Identifying the given number is valid number or not


#include <stdio.h>
#include<string.h>
int main()
{
    char a[500];
    int i,l,c=1,k=0;
    scanf("%s",a);
    l=strlen(a);
    if(a[0]=='+'||a[0]=='-'||(a[0]>='0'&&a[0]<='9'))
    {
        for(i=1;i<l;i++)
        {
            if(a[i]=='.')
            {
             k++;
             if(k>1)
             {
             printf("invalid");
             return 0;
             }
            }
            else if((a[i]>='0'&&a[i]<='9'))
            c++;
            else
            break;
        }
    if(c==l-1)
    printf("valid");
    else
    printf("invalid");
    }
    else
    printf("invalid");
    return 0;
}

 https://meet.google.com/tcg-zgzv-dye