-3
int sweet(int l,int n,int m )
{  
            if(m==0)

                return l;
            if(l>=n)
                return sweet(1,n,m-1);
            else
            return sweet(l+1,n,m-1);
}

int display(int d)
{    
    if(d==0)

      return 0;
      else
{
     int  n,m,s;

        scanf("%d %d %d",&n,&m,&s);

       printf("%d\n",sweet(s-1,n,m));

       return display(d-1);}
}

int main()
{
    int t;

    scanf("%d",&t);

        display(t);
}
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83

1 Answers1

0

Timeout error appears to be related to the scanf. If you look at the man page, scanf takes input from standard in. If the specific digits are not present in stdin, the program will hang as scanf will continue waiting for what it's looking for to appear.

Cheetaiean
  • 901
  • 1
  • 12
  • 26