I am hoping some one can help me out. I am trying to write a program that can read in 10 float numbers and print out their values to the screen. I also need to determine the largest, smallest, sum, average. I need to use an array. I have typed up alot of the code already, but I am having problems trying to compile what I have coded so far. Below is my code. Any input would be appreciated.
Code:#include <stdio.h> // for library function: printf // function main begins program execution main() { int i; // counter float n[10]; // n is an array of 10 integers float sum = 0; // sum of the array float average, smallest, largest; printf( "Enter 10 float numbers:\n" ); scanf( "%f", &n[10] ); // initialise elements of array to 0 for ( i = 0; i < 10; i++ ) { n[i] = 0; // set element at location i to 0 } // end for // sum of contents of array n for ( i = 0; i < 10; i++ ) { sum += n[i]; } // end for // average of contents of array n for ( i = 0; i < 10; i++ ) { sum / n[i]; } // end for // arrange array in ascending order for ( i = 0; i < n - 1; i++ ) { for j = 0; j < n - 1 - i; j++ ) { inOrder( &num[j], &num[j+1] ); } // end for // smallest number in array n **I have not done this as yet** // largest numnber in array n **I have not done this as yet** printf( "The sum of array n is %f\n", sum ); printf( "The avarage of array n is %f\n", average ); printf( "The array in ascending order is %f\n", n[10] ); printf( "The smallest number of array n is %f\n", smallest ); printf( "The largest number of array n is %f\n", largest ); return 0; // indicates successful termination } // end function main



LinkBack URL
About LinkBacks



: