Question

In: Computer Science

1. (50 pts) Write a C program that generates a 2D array-of-double and finds the indexes...

1. (50 pts) Write a C program that generates a 2D array-of-double and finds the indexes of the largest value stored in the 2D array. Specific requirements: (1) Your main function defines the 2D array a. You will need to prompt the user to specify the size of the 2D array b. You will need to prompt the user to put in numbers to initialize the array (2) Write a function to display the array that is visualized as rows and columns (3) Write a function that finds the indexes of the largest value stored in a 2D array-of double. (4) Print the resulting indexes in your main function.

Solutions

Expert Solution

#include <stdio.h>

#include <string.h>

#include <math.h>

#include <stdlib.h>

#include <float.h>

#define length 100

//structure for returning row and column

struct result {

    int row, column;

};

typedef struct result Struct;

  

//function for display 2D array of doubles

void Display_array(int rsize,int csize , double arr[length][length]) {

    int i, j;

    for(i=0;i<rsize;i++){

        for(j=0;j<csize;j++){

            printf("%lf ", arr[i][j]);

        }

        printf("\n");

    }

}


//function for comaring double elements

int compares(double x, double y){

    double xx=0.00000000;

    if((x-y)<xx){

        return 0;

    }

    return 1;

}

//function for returning index of largest element

Struct find(int rsize,int csize , double arr[length][length]){

    int i, j;

    Struct ans;

    int l_element_row=-1, l_element_column=-1;

    double largest=-DBL_MAX;

    for(i=0;i<rsize;i++){

        for(j=0;j<csize;j++){

            if(compares(arr[i][j], largest)){

                largest=arr[i][j];

                l_element_row=i, l_element_column=j;

            }

        }

    }

    ans.row=l_element_row;

    ans.column=l_element_column;

    return ans;

}


int main() {

    int row=0, column=0;

    double arr[length][length];

    //struct answer for returning row and column

    Struct answer;

    //input size of 2D array

    scanf("%d %d",&row,&column);

    //input element of 2D array

    int i, j;

    for(i=0;i<row;i++){

        for(j=0;j<column;j++){

            scanf("%lf",&arr[i][j]);

        }

    }

    //Display 2D array with function Display_array();

    Display_array(row, column, arr);

    //calling functin find for largest element row and column

    answer=find(row , column, arr);

    //printing row and column of largest element in 2D array of Double indexing from 0;

    printf("Largest Element \n Row=> %d \n Column=> %d", answer.row, answer.column);

    return 0;

}


Related Solutions

Write a program in C to perform the following: Generates an array of 10 double random...
Write a program in C to perform the following: Generates an array of 10 double random values between 1.0 and 100.0 – assume these are prices for 10 items that a store sells Generates an array of 10 integer random values between 0 and 200 – assume that these are the number of items/units (first array) sold Generate another array called “itemSale” which would contain the total sale for each item. Calculate the total sale for this store and display...
Write a C program that generates the following 2D array. 64   32   16   8   4   2  ...
Write a C program that generates the following 2D array. 64   32   16   8   4   2   1 32   32   16   8   4   1   1 16   16   16   8   4   2   1 8   8   8   8   4   2   1 4   4   4   4   4   2   1 2   2   2   2   2   2   1 1   1   1   1   1   1   1
i want a program in java that finds the shortest path in a 2D array with...
i want a program in java that finds the shortest path in a 2D array with obstacles from source to destination using BFS and recursion. The path must be stored in a queue. The possible moves are left,right,up and down.
java 1.) a method to append a 2d double array at the right of another 2d...
java 1.) a method to append a 2d double array at the right of another 2d double array, return a new array. E.g. numss1: {{1, 2}, {3, 4, 5}, {6}}, numss2: {{7}, {8, 9}}, return {{1, 2, 7}, {3, 4, 5, 8, 9}, {6}}
In C programming: Write a program that initializes an array-of-double and then copies the contents of...
In C programming: Write a program that initializes an array-of-double and then copies the contents of the array into another arrays. To make the copy, use a function with array notation. This function takes two arguments the name of the target array and the number of elements to be copied. That is, the function calls would look like this, given the following declarations: double source[5] ={1.1, 2.2, 3.3., 4.4, 5.5}; double target1[5]; double target2[5]; copyarr(source, target1, 5);
Write a Java program to randomly create an array of 50 double values. Prompt the user...
Write a Java program to randomly create an array of 50 double values. Prompt the user to enter an index and prints the corresponding array value. Include exception handling that prevents the program from terminating if an out of range index is entered by the user. (HINT: The exception thrown will be ArrayIndexOutOfBounds) *Please do it in eclipse and this is java language*
C++ Write a program to declare an array of double of size 25, ask the user...
C++ Write a program to declare an array of double of size 25, ask the user to input all array elements from the keyboard, then write a function named out_of_order that will test this array for the condition a[0] >= a[1] >= a[2] >= ... > a[24] The function returns a -1 if the elements are not out of order, otherwise it returns the index of the first element that is out of order. Explain what you do to avoid...
write a c++ program. Define a class ‘Matrix’ which contain 2D int array ‘m’ of size...
write a c++ program. Define a class ‘Matrix’ which contain 2D int array ‘m’ of size 3x3 as private member.        There should be two public methods within the class definition namely: void setMatrixValue(int i, int j); that should set m[i][j] with user defined values int getMatrixValue(int i, int j); that should return m[i][j] Make a global function named ‘CrossProduct(Matrix m1, Matrix m2)’ that should compute the marix multiplication
Write a method that displays every other element of an array. Write a program that generates...
Write a method that displays every other element of an array. Write a program that generates 100 random integers between 0 and 9 and displays the count for each number. (Hint: Use an array of ten integers, say counts, to store the counts for the number of 0s, 1s, . . . , 9s.) Write two overloaded methods that return the average of an array with the following headers:      public static int average(int[] intArray)        public static double average(double[] dArray) Also,...
Write a program that generates a random number between 1 and 50 and asks the user...
Write a program that generates a random number between 1 and 50 and asks the user to guess it. As a hint, it tells the user how many divisors it has, (excluding 1 and the number itself). Each time the user makes a wrong guess, it displays "Wrong" and says if the guess was too low or too high, until the user gets it right, in which case it says "Right" and says how many trials it took to guess...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT