Why am I getting segmentation fault? And how can I resolve such kind of errors?
you have done some mistake
- you forgot to decrease k in while loop
- you have to consider 3 case
a) if(k>n)
b) if(k==n)
c) if (k<n)
i have done all required changes you can check
Modified Code
if you have more doubts regarding this feel free to ask
i hope this helps
if yes hit a like and don’t forgot to mark doubt as resolved 
Thank you so much …
But why are we doing k=k%n when k>n …
because we cannot append last k elements ( when k is greater than length ) so inorder to get k in the range of linked list
we do k= k%n
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.