Untitled

 avatar
unknown
plain_text
a year ago
7.6 kB
5
Indexable


// na(w) mod 2 ! nb(w) mod3
#include <stdio.h>
#include <stdlib.h>
#include <string.h>



int main()
{

    int choice;
    while(1)
    {
    printf("\n enter choice : \n1-> to enter new string \n2-> exit\n");
    scanf("%d",&choice);

    switch(choice)
    {
    case 1:
    char str[100];
    printf("\n Enter string : ");
    scanf("%s",str);
    int i=0;

    int q=0;
    for(int j=0;j<strlen(str);j++)
    {

        if(str[i]!='a' && str[i]!='b')
        {
          printf("\nINVALID STRING");
          break;
        }
       switch(q)
       {
          case 0: if(str[i]=='a'){
                    q=1;

          }

                    else
                    q=2;
                    i++;
                break;
           case 1: if(str[i]=='b')
           {
           q=3;

           }

                    else
                    q=0;
                    i++;
                    break;
          case 2: if(str[i]=='a')
                    q=3;

                    else
                    q=4;
                     i++;
                    break;
        case 3: if(str[i]=='a')
                    q=2;
                    else
                    q=5;
                    i++;
                    break;
        case 4: if(str[i]=='a')
                    q=5;
                    else
                    q=0;
                    i++;
                    break;
        case 5: if(str[i]=='a')
                    q=4;
                    else
                    q=1;
                    i++;
                    break;


       }
    }
    if(q==1 || q==4 || q==2 || q==5)
    printf("\n ACCEPTED");
    else
    printf("\n NOT ACCEPTED");
    break;

    case 2: exit(0);
    break;
}

}
    return 0;
}















// binary numbers divisible by 6
#include <stdio.h>
#include <stdlib.h>
#include <string.h>



int main()
{

    int choice;
    while(1)
    {
    printf("\n enter choice : \n1-> to enter new string \n2-> exit\n");
    scanf("%d",&choice);

    switch(choice)
    {
    case 1:
    char str[100];
    printf("\n Enter string : ");
    scanf("%s",str);
    int i=0;

    int q=0;
    for(int j=0;j<strlen(str);j++)
    {

        if(str[i]!='0' && str[i]!='1')
        {
          printf("\nINVALID STRING");
          break;
        }
       switch(q)
       {
          case 0: if(str[i]=='0'){
                    q=0;

          }

                    else
                    q=1;
                    i++;
                break;
           case 1: if(str[i]=='0')
           {
           q=2;

           }

                    else
                    q=3;
                    i++;
                    break;
          case 2: if(str[i]=='0')
                    q=4;

                    else
                    q=5;
                     i++;
                    break;
        case 3: if(str[i]=='0')
                    q=0;
                    else
                    q=1;
                    i++;
                    break;
        case 4: if(str[i]=='0')
                    q=2;
                    else
                    q=3;
                    i++;
                    break;
        case 5: if(str[i]=='0')
                    q=4;
                    else
                    q=5;
                    i++;
                    break;


       }
    }
    if(q==0)
    printf("\n ACCEPTED");
    else
    printf("\n NOT ACCEPTED");
    break;

    case 2: exit(0);
    break;
}

}
    return 0;
}

















// binary numbers divisible by 2 but not 3
#include <stdio.h>
#include <stdlib.h>
#include <string.h>



int main()
{

    int choice;
    while(1)
    {
    printf("\n enter choice : \n1-> to enter new string \n2-> exit\n");
    scanf("%d",&choice);

    switch(choice)
    {
    case 1:
    char str[100];
    printf("\n Enter string : ");
    scanf("%s",str);
    int i=0;

    int q=0;
    for(int j=0;j<strlen(str);j++)
    {

        if(str[i]!='0' && str[i]!='1')
        {
          printf("\nINVALID STRING");
          break;
        }
       switch(q)
       {
          case 0: if(str[i]=='0'){
                    q=0;

          }

                    else
                    q=1;
                    i++;
                break;
           case 1: if(str[i]=='0')
           {
           q=2;

           }

                    else
                    q=3;
                    i++;
                    break;
          case 2: if(str[i]=='0')
                    q=4;

                    else
                    q=5;
                     i++;
                    break;
        case 3: if(str[i]=='0')
                    q=0;
                    else
                    q=1;
                    i++;
                    break;
        case 4: if(str[i]=='0')
                    q=2;
                    else
                    q=3;
                    i++;
                    break;
        case 5: if(str[i]=='0')
                    q=4;
                    else
                    q=5;
                    i++;
                    break;


       }
    }
    if(q==2 || q==4)
    printf("\n ACCEPTED");
    else
    printf("\n NOT ACCEPTED");
    break;

    case 2: exit(0);
    break;
}

}
    return 0;
}














// decimal numbers divisible by 6
#include <stdio.h>
#include <stdlib.h>
#include <string.h>



int main()
{

    int choice;
    while(1)
    {
    printf("\n enter choice : \n1-> to enter new string \n2-> exit\n");
    scanf("%d",&choice);

    switch(choice)
    {
    case 1:
    char str[100];
    printf("\n Enter string : ");
    scanf("%s",str);
    int i=0;

    int q=0;
    for(int j=0;j<strlen(str);j++)
    {

        if(str[i]!='0' && str[i]!='1' && str[i]!='2' && str[i]!='3' && str[i]!='4' && str[i]!='5' && str[i]!='6' && str[i]!='7' && str[i]!='8' && str[i]!='9')
        {
          printf("\nINVALID STRING");
          break;
        }
       switch(q)
       {
          case 0: if(str[i]=='0' || str[i]=='4' || str[i]=='8')
                    q=0;

          

                    else if(str[i]=='1' || str[i]=='5' || str[i]=='9')
                    q=1;
                    else if(str[i]=='2' || str[i]=='6')
                    q=2;
                    else
                    q=3;
                    i++;
                break;
           case 1: if(str[i]=='0' || str[i]=='4' || str[i]=='8')
                    q=2;

          

                    else if(str[i]=='1' || str[i]=='5' || str[i]=='9')
                    q=3;
                    else if(str[i]=='2' || str[i]=='6')
                    q=0;
                    else
                    q=1;
                    i++;
                break;
         case 2: if(str[i]=='0' || str[i]=='4' || str[i]=='8')
                    q=0;

          

                    else if(str[i]=='1' || str[i]=='5' || str[i]=='9')
                    q=1;
                    else if(str[i]=='2' || str[i]=='6')
                    q=2;
                    else
                    q=3;
                    i++;
                break;
        case 3: if(str[i]=='0' || str[i]=='4' || str[i]=='8')
                    q=2;

          

                    else if(str[i]=='1' || str[i]=='5' || str[i]=='9')
                    q=3;
                    else if(str[i]=='2' || str[i]=='6')
                    q=0;
                    else
                    q=1;
                    i++;
                break;
        


       }
    }
    if(q==0)
    printf("\n ACCEPTED");
    else
    printf("\n NOT ACCEPTED");
    break;

    case 2: exit(0);
    break;
}

}
    return 0;
}

Editor is loading...
Leave a Comment