## C++ Program To Find The Sum Of Last N Nodes Of The Given Linked List

``````// C++ implementation to find the sum of
// last 'n' nodes of the Linked List
#include <bits/stdc++.h>
using namespace std;

struct Node
{
int data;
struct Node* next;
};

// Function to insert a node at the
// beginning of the linked list
int new_data)
{
// Allocate node
struct Node* new_node = new Node;

// Put in the data
new_node->data = new_data;

// Link the old list to the new node

// Move the head to point to the
// new node
}

// Function to recursively find the sum of last
// 'n' nodes of the given linked list
int* n, int* sum)

{
return;

// Recursively traverse the remaining nodes

// if node count 'n' is greater than 0
if (*n > 0)
{
// Accumulate sum

// Reduce node count 'n' by 1
--*n;
}
}

// Utility function to find the sum of
// last 'n' nodes
int n)
{
// if n == 0
if (n <= 0)
return 0;

int sum = 0;

// Find the sum of last 'n' nodes

// Required sum
return sum;
}

// Driver code
int main()
{

int n = 2;
cout << "Sum of last " << n <<
" nodes = " <<