Correct way of calculating sum of a tab ?

1
2
3
for(i=1;i<=parties;i++)
              totalM=totalM+tabC[i];
              printf("%d",&totalM)


I'm just trying to sum up all the values of my tabC, this is what I thought was going to work but it gives me a number that is way incorrect; IE it should be 15 but it'll show 26865840 regardless of what i put in the tabC.
Try to rewrite the code snip the following way


1
2
3
totalM = 0;
for ( i = 0; i < parties; i++ ) totalM += tabC[i];
printf( "%d", totalM ); 

I hope this is because of totalM variable is not initialized
@meeram
I hope this is because of totalM variable is not initialized


I think that it more resembles that he is using an incorrect range of indexes and an invalid function call
printf("%d",&totalM)

Ah....yes....I agree on that
Topic archived. No new replies allowed.