Make sum using List

Suman Barik
0

// CPP program to illustrate

// Application of empty() function

#include <forward_list>

#include <iostream>

using namespace std;


int main()

{

int sum = 0;

forward_list<int> myforwardlist{ 1, 5, 6, 3, 9, 2 };

while (!myforwardlist.empty()) {

sum = sum + myforwardlist.front();

myforwardlist.pop_front();

}

cout << sum;

return 0;

}


Tags

Post a Comment

0Comments
Post a Comment (0)