Int main ()
{
Int b, k, sum;
Printf (" please enter a positive integer number: \ n ");
The scanf (" % d ", & amp; K);
Int a, [k].
Printf (" please enter a positive integer: \ n ");
for(b=0; B<=(k - 1); B++)
{
The scanf (" % d ", & amp; [b]);
If (a [b] % 2! Sum==0) sum + a, [b].
}
Printf (" % d ", sum);
return 0;
}
CodePudding user response:
Don't use variable array length, or you can use the dynamic application memoryCodePudding user response:
What do you mean? Novice is not very goodCodePudding user response:
C language array length requirement is constant values,The scanf (" % d ", & amp; K);
Int a, [k].
This is no good
CodePudding user response:
Then how should I say input quantity? Last time, I also in this way, not seen such a mistakeCodePudding user response:
Some compilers support the way of the definition of arrayCodePudding user response:
Run your screenshots to look atCodePudding user response:
Int a, [k].To int a [100];//array length with constant
Or change to
Int * a=(int *) malloc (sizeof (int) * k);//dynamic application memory, and finally remember free (a)
In addition, the sum uninitialized, add in front of the for loop
sum=0;