adding variables for, for loop

I have a structure which contains n number of elements. For example:
stFruits : apple, grapes, strawberry, pear, kiwi, melon, papaya, mango, orange, sweetlime ..... etc

Now i have to write a for loop as follows:

int i;
int j;

j=stFruits.apple+stFruits.grapes+stFruits.pear+.... and so on...

for(i=0;i<j;i++)
{
}

What i would like to know is , is there an other way to represent the sum of all elements in the structure instead of adding in the above way???

Iam very new to Programming... and hope to get an answer...

Not really, you could avoid using the j and check for

for(i=0;i<stFruits.apple+...;i++) {
}

I don't think that there is any other way to get the sum of structure elements. Maybe you could declare them in an array and use a loop to get the sum? If not, then you have no choice but to go about it this way.

one more way;
but an extra element to be populated in the node.

your prev definition of the structure.

struct stFruits
{
  int fruittype;
  struct stFruits *next;
};

modifiy the structure definition as

struct stFruits
{
  int fruittype;
  long cumSum;
  struct stFruits *next;
};

when adding each of the element to the list of nodes,
just populate the cumSum
and to retrieve the totalSum just read the lastelement.cumSum,
that would do.

Thank u so much for the reply.