/* ---------------------------------------------------------------------- // Figure 2.8: A C program for the average algorithm. // Compute and display the average of three numbers. // ---------------------------------------------------------------------- */ #include int main( void ) { double n1, n2, n3; /* The three input numbers. */ double average; /* The average of the three numbers. */ printf( "\nCompute the average of 3 Numbers\n" ); printf( "--------------------------------\n" ); printf( "Please input 3 numbers: " ); scanf( "%lg%lg%lg", &n1, &n2, &n3 ); /* Read the numbers. */ printf( "Averaging %g, %g, %g;", n1, n2, n3 ); /* Echo the inputs. */ average = (n1 + n2 + n3 ) / 3.0; /* Average is sum / 3. */ printf( " the average is %g\n\n", average ); /* Print the average. */ }