Write a C program to verify the string (aa|bb)*


#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
          char str[20];
          int flag=0,i;
          clrscr();

          printf("\n Enter the String:-");
          gets(str);

          if(str[0]=='\0'||(str[0]=='a' && str[1]=='a') ||( str[0]=='b' && str[1]=='b'))
          {
                   for(i=2;i<strlen(str);i+=2)
                   {
                             if((str[i]=='a' || str[i+1]=='a'))
                                      flag=1;
                             if((str[i]=='b' || str[i+1]=='b'))
                                      flag=1;
                             else
                             {
                                      flag=0;
                                      goto Next;
                             }
                   }
          Next: if(flag==1)
                             printf("\n Validddd.....");
                   else
                             printf("\n INValid String");
          }
          else
          {
                   printf("\nInvalid");
          }
          getch();
}

Related Posts Plugin for WordPress, Blogger...

Engineering material

GTU IDP/ UDP PROJECT

GTU IDP/ UDP PROJECT

Patel free software download

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP