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...
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*
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 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...
Program in C: Write a program in C that reorders the elements in an array in...
Program in C: Write a program in C that reorders the elements in an array in ascending order from least to greatest. The array is {1,4,3,2,6,5,9,8,7,10}. You must use a swap function and a main function in the code. (Hint: Use void swap and swap)
Write a program in C that declares the following array: int. array[] = { 1, 2,...
Write a program in C that declares the following array: int. array[] = { 1, 2, 4, 8, 16, 32 } Then write some code that accepts a number between 0 and 5 from the user and stores it in a variable called "index". Write some code that retrieves the item specified by the index, like this: int item = array[index]; Then write code that outputs the corresponding array entry based on the number the user entered. Example output: The...
Write a java program of a multiplication table of binary numbers using a 2D array of...
Write a java program of a multiplication table of binary numbers using a 2D array of integers.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT