I wrote this code but this isn't working

Can you tell what’s wrong in this and its simpler version if possible.

hello @apoorvagupta1
the issue is in ur second for loop.
ur while loop condition should be

while(slow->next!=temp->next)

and then do this slow->next=NULL; outside the while loop