Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include<string.h>
- int main(){
- int i,state_a=0,state_b,state_n;
- char s[100];
- printf("Enter your string");
- gets(s);
- int len=strlen(s);
- for(i=0;i<len;i++){
- if(s[i]=='a')
- {
- state_a=state_a+1;
- }
- else if(s[i]=='b'){
- if((s[i+1])=='a'){
- state_n=1;
- break;
- }
- else(state_b=state_b+1);
- }
- else if(s[i]!='a' || s[i]!='b')
- {
- state_n=1;
- break;
- }
- else
- continue;
- }
- if(state_a==len)
- {
- printf("the string is not recognised");
- }
- else if(state_b==len)
- {
- printf("the string is recognised under the 'a*b+'");
- }
- else if(state_n==1){
- printf("the string is not recognised");
- }
- else
- {
- printf("the string is recognised under the 'a*b+'");
- }
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement