Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define ROWS 3
- #define COLS 5
- void storage(int rows, int cols, double array[rows][cols]);
- void row_average(int rows, int cols, double array[rows][cols]);
- double average(int rows, int cols, double array[rows][cols]);
- double largest(int rows, int cols, double array[rows][cols]);
- int main(void){
- double array1[ROWS][COLS];
- printf("Enter 3 sets of 5 double numbers each. Press enter after every 5 numbers.\n");
- storage(ROWS, COLS, array1);
- row_average(ROWS, COLS, array1);
- printf("The average of all the values is %.2f.\n", average(ROWS, COLS, array1));
- printf("The biggest value of the 15 values is %.2lf.\n", largest(ROWS, COLS, array1));
- return 0;
- }
- void storage(int rows, int cols, double array[rows][cols]){
- int i, j;
- for(i=0; i<ROWS; i++){
- for(j=0; j<COLS; j++){
- scanf("%lf", &array[i][j]);
- }
- }
- }
- void row_average(int rows, int cols, double array[rows][cols]){
- int i, j;
- double subtot=0;
- for(i=0; i<ROWS; i++){
- for(j=0; j<COLS; j++){
- subtot+=array[i][j];
- }
- printf("For row %d, the average is %.2lf.\n", i+1, subtot/COLS);
- subtot=0;
- }
- }
- double average(int rows, int cols, double array[rows][cols]){
- int i, j;
- double total=0, average;
- for(i=0; i<ROWS; i++){
- for(j=0; j<COLS; j++){
- total+=array[i][j];
- }
- }
- average=total/(rows*cols);
- return average;
- }
- double largest(int rows, int cols, double array[rows][cols]){
- int i, j;
- double biggest=-100000;
- for(i=0; i<ROWS; i++){
- for(j=0; j<COLS; j++){
- if(array[i][j]>biggest)
- biggest=array[i][j];
- }
- }
- return biggest;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement