What is the error in my code for Farmer Feb(under Practice(easy))?

#include<stdio.h>
#include<stdlib.h>

int main()
{
int x,y,t,a,b,ans,flag,i,j;
scanf("%d",&t);
while(t)
{
scanf("%d %d",&x,&y);
a=x+y;
if(a==2)
{
printf(“1\n”);
goto xy;
}
else if(a<5)
{
b=5-(a%10);
printf("%d\n",b);
goto xy;
}
else if(a<7)
{
b=7-(a%10);
printf("%d\n",b);
goto xy;
}
a=x+y+1;

    ab:
        if(a%10<=1)
        {
            b=1-(a%10);
            a=a+b;
            for(j=1;;j++)
            {for(i=3;i*i<=a;i++)
                {
                flag=0;
                if(a%i==0)
                {
                    flag=1;
                    break;
                }

                }
            if(flag==0)
               {
                    ans=a-x-y;
                    printf("%d\n",ans);
                    goto xy;
               }
               if(j%3==1 || j%3==0)
                    a+=2;
                else if(j%3==2)
                    a+=4;
            }
        }

        else if(a%10<=3)
        {
            b=3-(a%10);
            a=a+b;
            for(i=3;i*i<=a;i++)
                {
                flag=0;
                if(a%i==0)
                {
                    flag=1;
                    break;
                }
                }
                if(flag==0)
                {
                    ans=a-x-y;
                    printf("%d\n",ans);
                    goto xy;
                }
                a+=4;
                for(i=3;i*i<=a;i++)
                {
                flag=0;
                if(a%i==0)
                {
                    flag=1;
                    break;
                }
                }
                if(flag==0)
                {
                    ans=a-x-y;
                    printf("%d\n",ans);
                    goto xy;
                }
                a+=2;
                for(i=3;i*i<=a;i++)
                {
                flag=0;
                if(a%i==0)
                {
                    flag=1;
                    break;
                }
                }
                if(flag==0)
                {
                    ans=a-x-y;
                    printf("%d\n",ans);
                    goto xy;
                }
                a+=2;
                goto ab;
        }

        else if(a%10<=7)
        {
            b=7-(a%10);
            a=a+b;
            for(i=3;i*i<=a;i++)
                {
                flag=0;
                if(a%i==0)
                {
                    flag=1;
                    break;
                }
                }
                if(flag==0)
                {
                    ans=a-x-y;
                    printf("%d\n",ans);
                    goto xy;
                }
                a+=2;
                for(i=3;i*i<=a;i++)
                {
                flag=0;
                if(a%i==0)
                {
                    flag=1;
                    break;
                }
                }
                if(flag==0)
                {
                    ans=a-x-y;
                    printf("%d\n",ans);
                    goto xy;
                }
                a+=2;
                goto ab;
        }

        else if(a%10<=9)
        {
            b=9-(a%10);
            a=a+b;
            for(i=3;i*i<=a;i++)
                {
                flag=0;
                if(a%i==0)
                {
                    flag=1;
                    break;
                }
                }
                if(flag==0)
                {
                    ans=a-x-y;
                    printf("%d\n",ans);
                    goto xy;
                }
                a+=2;
                goto ab;
        }
        xy:
            t--;
}
return 0;

}

Your algorithm seems to be wrong. Take a look at this code.This is my code. I think you will get the idea. It is easy and for more details check this editiorial

1 Like

One advice that i can give you is, (i hope that you are just new to the world of programming) it is better not to use ‘goto’ in your code. it is not a good practice as you go further in the world of programming. You will not be able to de-bug your code easily. Take a look at this post
I wish you all the success in the world of programming :slight_smile:

1 Like

Here is your debugged code. I have made some major changes over there. But i have commented it very well so that you will understand it well. If you have any-doubt you are free to ask me :slight_smile:

Happy Coding

1 Like

hello! i have modified my question… this code is for farmer feb… please help!

:smiley: let me look. hehe after reading the code i was like o.O :stuck_out_tongue:

If you understood my answer can you please accept it so that we can close the question ? :slight_smile: