9
Somme des éléments d'un tableau
- #include <stdio.h>
- double sum( const float tab[], const unsigned siz ) {
- double sum; /* same name! */
- int i;
- for ( sum = 0.0, i = 0; i < siz; i++ )
- sum += tab[ i ];
- return sum;
- }
- main() {
- float f[] = { 1.0, 1.0/10, 1.0/100, 1.0/1000, 1.0/10000, 1.0/100000, 1.0/1000000 };
- printf( "sum=%f\n", sum( f, sizeof(f)/sizeof(float)) );
- }
Commentaires