0

I am having trouble understanding how rand function is operating here.Can you comment the process?

// Created by ANIK #include <stdio.h> #include <stdlib.h> #include <time.h> float sumline( float arr[ 12 ][ 12 ], int L1 ) { float sum = 0; for ( int i = 0; i < 12; i++ ) { sum += arr[ L1 ][ i ]; } return sum; } float averageline( float arr1[ 12 ][ 12 ], int L2 ) { return sumline( arr1, L2 ) / 12.0f; } int main() { srand( ( unsigned )time( NULL ) ); float array[ 12 ][ 12 ], rf = 5.0f; for ( int i = 0; i < 12; i++ ) { // ** float sum_this_row = 0.0f; for ( int j = 0; j < 12; j++ ) { // scanf( "%f", &array[ i ][ j ] ); array[ i ][ j ] = ( float )rand( ) / ( float )( RAND_MAX * rf ); // ** sum_this_row += array[ i ][ j ]; // ** printf( "%.1f ", array[ i ][ j ] ); } // ** printf( "=> %f", sum_this_row ); // ** putchar( 10 ); } int line; scanf( "%d", &line ); // fflush( stdin ); char choose; scanf( " %c", &choose ); // fflush( stdin ); if ( choose == 'S' ) { printf( "%f", sumline( array, line ) ); } else if ( choose == 'A' ) { printf( "%f", averageline( array, line ) ); } return 0; }

10th Sep 2022, 4:23 PM
ANIK
ANIK - avatar
1 Resposta
+ 2
If you LINK your code, people will find it easier to read
10th Sep 2022, 4:24 PM
Lisa
Lisa - avatar