Question

Given the following 2D array double nums[MAXROW][MAXCOL] = {{ 7, 12, 8, 23, 43, 16, 9, 15}, {21, 7, 14, 48, 13, 6, 43, 29), {
0 0
Add a comment Improve this question Transcribed image text
Answer #1

HERE THE PROGRAM IS DONE WITH C++ LANGUAGE

IN THIS PROGRAM ALL THE ARGUMENTS ARE PASSED IN THE FUNCTION.

PROGRAM

#include<iostream>
/* here we define macro of MAXROW and MAXCOL as 20 */
# define MAXROW 20
# define MAXCOL 20
using namespace std;
/* totalRow function has three arguments */
totalRow(double nums[MAXROW][MAXCOL],int numRows,int numCols)
{
   int i,j;
   double s=0.0;
   /* scan the 2d array */
   for(i=0;i<numRows;i++)
   {
   for(j=0;j<numCols;j++)
   {
       /* check if row index is 2 then the values will be added */  
   if(i==2)
   {
   /* added values */
       s=s+   nums[i][j];
       }
    }
   }
   /* print the total */
   cout<<"Total is : " <<s;
}
main()
{
   /* define and initialize the 2d array */
   double nums[MAXROW][MAXCOL]={{7,12,8,23,43,16,9,15},
   {21,7,14,48,13,6,43,29},
   {11,2,17,91,36,14,65,43},
   {18,5,47,38,52,1,18,26}};
     
/* total row and colum numbers are given */
   int numRows=4;
int numCols=8;
/* call function totalRow with array, number of rows and number of columns */
totalRow(nums,numRows,numCols);
}

SCREEN SHOT

#include<iostream> /* here we define macro of MAXROW and MAXCOL as 20 */ # define MAXROW 20 # define MAXCOL 20 using namespac

main() /* define and initialize the 2d array */ double nums[MAXROW][MAXCOL]={{7,12,8,23,43,16,9,15}, {21, 7, 14,48,13,6,43,29

OUTPUT

D. C:\Users\cse\Documents\row_total.exe Total is : 279 Process exited after 9.0162 seconds with return value o Press any key

Add a comment
Know the answer?
Add Answer to:
Given the following 2D array double nums[MAXROW][MAXCOL] = {{ 7, 12, 8, 23, 43, 16, 9,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use C++ (2D Array) Write a program which: 1. Assigns data given below into the 2D...

    Use C++ (2D Array) Write a program which: 1. Assigns data given below into the 2D array of integers which is 10x10. 2. Prints out the contents of the 2D array after assigning the data to make sure correct data was assigned. 3. Figures out and prints out the square root of the sum of ALL the elements in the 2D array. 4. Figures out and prints out the average of ALL THE ELEMENTS in the 2D array. 5. Figures...

  • C# 1. Given two lengths between 0 and 9, create an rowLength by colLength matrix with...

    C# 1. Given two lengths between 0 and 9, create an rowLength by colLength matrix with each element representing its column and row value, starting from 1. So the element at the first column and the first row will be 11. If either length is out of the range, simply return a null. For exmaple, if colLength = 5 and rowLength = 4, you will see: 11 12 13 14 15 21 22 23 24 25 31 32 33 34...

  • This is the contents of Lab11.java import java.util.Scanner; import java.io.*; public class Lab11 { public static...

    This is the contents of Lab11.java import java.util.Scanner; import java.io.*; public class Lab11 { public static void main(String args[]) throws IOException { Scanner inFile = new Scanner(new File(args[0])); Scanner keyboard = new Scanner(System.in);    TwoDArray array = new TwoDArray(inFile); inFile.close(); int numRows = array.getNumRows(); int numCols = array.getNumCols(); int choice;    do { System.out.println(); System.out.println("\t1. Find the number of rows in the 2D array"); System.out.println("\t2. Find the number of columns in the 2D array"); System.out.println("\t3. Find the sum of elements...

  • Write a C function  f such that … function  f accepts, as input, … a two-dimensional array of...

    Write a C function  f such that … function  f accepts, as input, … a two-dimensional array of integers in which each row has three columns the number of rows in the array function  f returns the sum of the odd integers in the given array of integers and returns zero if there are no odd integers in the array COMPILER STACK TRACE None PROGRAM EXECUTION STACK TRACE None COMPILER COMMAND LINE ARGUMENTS -lm INPUT OF THE TEST CASE 1 #define NUM_ROWS 5...

  • Refer to the following array definition for questions 1 & 2 int numberArray[9)[11] 1. Write a...

    Refer to the following array definition for questions 1 & 2 int numberArray[9)[11] 1. Write a statement that assigns 145 to the first column of the first row of this array. 2. Write a statement that assigns 18 to the last column of the last row of this array. values is a two-dimensional array of floats, with 10 rows and 20 columns. Write code that sums all of the elements in the array and stores the sum in the variable...

  • An m×n array A of real numbers is a Monge array if for all i,j,k, and l such that 1≤i<k≤m and ...

    An m×n array A of real numbers is a Monge array if for all i,j,k, and l such that 1≤i<k≤m and 1≤j<l≤n , we have >A[i,j]+a[k,l]≤A[i,l]+A[k,j]> In other words, whenever we pick two rows and two columns of a Monge array and consider the four elements at the intersections of the rows and columns, the sum of the upper-left and lower-right elements is less than or equal to the sum of the lower-left and upper-right elements. For example, the following...

  • Line number 9 contains the code line that declares the result array ( asked in another...

    Line number 9 contains the code line that declares the result array ( asked in another question of this exam). On Line number 11 where col_ contains the correct statement ( asked in another question of this exam) Question: Write the codeline (single line) to compute the matrix multiplication of "frstMatrix" and "scndMatrix". For this question you will write a code line for line number 17 1 package ok4; 2 //This java program multiplies two matrices 3 //represented with two...

  • Your assignment is to design a TicketManager class that can keep track of the number of...

    Your assignment is to design a TicketManager class that can keep track of the number of seats available in a theater’s auditorium. The TicketManager class should have a two-Dimensional array, which has 15 rows and 30 columns for all the seats available in the auditorium, also an array of double to keep track of the price of tickets for each row. Each row has a different price. Use the following UML diagram to design the class: -------------------------------------------------------------------- + NUMROWS :...

  • The ExceptionLab class provided: – Creates an array of 100 elements and fills it with random...

    The ExceptionLab class provided: – Creates an array of 100 elements and fills it with random numbers from 1 to 100. – It asks the user for an index value between 0 and 99. – Prints the element at that position. – If a number > 99 is entered by the user, the class will abort with an ArrayIndexOutOfBoundsException • Modify the ExceptionLab: – Add a try-catch clause which intercepts the ArrayIndexOutOfBounds and prints the message: Index value cannot be...

  • The following program simulates shuffling a deck of cards. (The line numbers are not ) part of the code). Without changing its functionality, rewrite the program by replacing the 2D array card [5...

    The following program simulates shuffling a deck of cards. (The line numbers are not ) part of the code). Without changing its functionality, rewrite the program by replacing the 2D array card [52] [2] with a double pointer char **card and replacing the code between line 12 and line 26 with a function. The function prototype could be void shuffleCards (char **, char [, char [) 1 7/Shuffling cards 2 4 using namespace std; 6 main() #include #include <cstdlib> <iostream>...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT