Is my logic for nth node from last correct?Its not printing anything

void nfromlast(node*&head,int g,int num,int ans,int h)
{
cin>>num;
nodetemp=head;
while(temp->next!=nullptr)
{
g++;
temp=temp->next;
}
ans = g-num;
node
ptr=head;
while(ptr->next!=nullptr)
{
h++;
if(h==ans)
{
cout<data;
cout<<“found at”<<h;
}
ptr=ptr->next;
}
return;
}

Hey @supratik260699
Seems like there is an error with the way you’re printing data.
It should be cout<data and not cout<data.

There is some problem its not showing correct symbol while typing here

Can you please paste the code on coding blocks IDE and send it once

@supratik260699 check this code, there were small fixes required. I’ve mentioned them in comments.

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.