Correct way of calculating sum of a tab ?
Nov 25, 2012 at 9:27pm UTC
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.
Nov 26, 2012 at 10:08am UTC
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 );
Nov 26, 2012 at 11:01am UTC
I hope this is because of totalM variable is not initialized
Nov 26, 2012 at 11:12am UTC
@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)
Nov 26, 2012 at 11:16am UTC
Ah....yes....I agree on that
Topic archived. No new replies allowed.