answersLogoWhite

0


Best Answer

A row is just a one-dimensional array so, given a pointer to the first element of a row of doubles and the number of doubles in the row, we can use the following algorithm:

// returns the largest double in an array of size count

double get_largest (double * p, unsigned count) {

if (p==NULL size==0) { /* invoke invalid argument handler */ }

double result = *p; // store first value in row (dereference the pointer)

while (--count) { // repeat for the remainder of the row

++p; // advance to the next element

if (*p > result) result = *p; // if the current element is larger, update stored value

}

return result; // return largest value

}

User Avatar

Wiki User

7y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C program to find the largest element in a row?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

The place in a spreadsheet where a row and a column intersect is called a?

A cell. In the periodic table an element fills that cell.


How do you initialize each element of a two-dimensional array alpha to 5?

Two-dimensional arrays are typically iterated through using nested for loops. If you had a 2-D array alpha with ints ROWS and COLS representing the number of rows and columns respectively, and ints row and col as iterators, the loop would look like this: for (row = 0; row < ROWS; row++){ for (col = 0; col < COLS; col++{ alpha[row][col] = 5; } }


How will you initialize a three-dimensional array thread 323. How will you refer the first and last element in this array?

The first element will be 0,0,0 and the last will be 2,1,2. It's always best to think of multi-dimensional arrays in terms of a one-dimensional array. That is, a 3x2x3 array is really a one-dimensional array of 3 elements (the first dimension), where each element is a 2x3 two-dimensional array, and where each of those 2x3 arrays is a one-dimensional array of 2 elements (the second dimension), where each element is a one-dimensional array of 3 elements (the third dimension). Thinking in these terms makes it much easier to visualise arrays with 4 or more dimensions. Arrays are always allocated contiguously, one element after the other. So the memory layout for your three dimensional array is as follows (where 000 means element 0,0,0): {{000, 001, 002}, {010, 011, 012}}, {{100, 101, 102}, {110, 111, 112}}, {{200, 201, 202}, {210, 211, 212}} The curly braces are merely notational, but they help to visualise the layout more clearly, dividing the memory into three groups of two groups of three elements. However, if we stack the three main groups one above the other it will be much easier to see visualise the structure: {000, 001, 002}, {010, 011, 012} {100, 101, 102}, {110, 111, 112} {200, 201, 202}, {210, 211, 212} If you look at each row you can clearly see that the first digit in each element is the same throughout that row. However, each row is really a two-dimensional array (of 2x3 elements), so each row is really a 2x3 table. The top row is therefore table 0, the middle row is table 1 and the bottom row is table 2. Let's look at table 0 more closely: Table 0: {000, 001, 002}, {010, 011, 012} Now let's stack the table's 2 elements so we can see the table more clearly: Table 0: {000, 001, 002} {010, 011, 012} Now the rows are identified by the second digit, where the top row is row 0 and the bottom row is row 1. Each row has three elements and the third digit identifies the column of that element (0, 1 or 2). Here's the complete structure: Table 0: Row 0: {000, 001, 002} Row 1: {010, 011, 012} Table 1: Row 0: {100, 101, 102} Row 1: {110, 111, 112} Table 2: Row 0: {200, 201, 202} Row 1: {210, 211, 212} From this we can clearly see that we can refer to any individual element through a table identifier (0, 1 or 2), a row identifier (0 or 1) and a column identifier (0, 1 or 2). Therefore to initialise this structure, we need to cycle through each identifier in turn. Here's how we do that using pseudo-code: given array A [3,2,3] for each table in 0 to 2 for each row in 0 to 1 for each column in 0 to 2 initialise A [table, row, column] next column next row next table


Find out the address of the element A452 where A is a 3-dimensional array with subscript limits 1 you 6 1 j 7 and 0 k 4 when A is in row major addressing Assume base address is 1000 and word size is 2?

1. Find out the address of the element A(4,5,2) where A is a 3-dimensional array with subscript limits 1≤ i ≤6, 1≤ j ≤7 and 0≤ k ≤4 when A is in row major addressing. Assume base address is 1000 and word size is 2.Answer:Array(depth,col,row) means A(4,5,2)Address= BASE+ ((depthindex*col_size+colindex) * row_size + rowindex) * Element_SizeADDRESS=1000+((4*7+5)*5+2)*2(1000+((33*5)+2)*2(1000+(167*2))(1000+334)1334


How do you write a program to find magic numbers?

#include<stdio.h> unsigned sum_row (unsigned* sq, const unsigned width, const unsigned row) { unsigned sum, col; sum = 0; for (col=0; col<width; ++col) sum += sq[row*width+col]; return sum; } unsigned sum_col (unsigned* sq, const unsigned width, const unsigned col) { unsigned sum, row; sum = 0; for (row=0; row<width; ++row) sum += sq[row*width+col]; return sum; } unsigned sum_diag (unsigned* sq, const unsigned width) { unsigned sum, row, col; sum = 0; for (row=0, col=0; row<width; ++row, ++col) sum += sq[row*width+col]; return sum; } unsigned sum_anti (unsigned* sq, const unsigned width) { unsigned sum, row, col; sum = 0; for (row=0, col=width-1; row<width; ++row, --col) sum += sq[row*width+col]; return sum; } bool is_magic (unsigned* sq, const unsigned width) { unsigned magic, row, col; magic = sum_row (sq, width, 0); for (row=1; row<width; ++row) if (magic!=sum_row(sq, width, row)) return false; for (col=0; col<width; ++col) if (magic!=sum_col(sq, width, col)) return false; if (magic!=sum_diag(sq, width)) return false; if (magic!=sum_anti(sq, width)) return false; return true; } int main () { const unsigned width = 3; unsigned a[width][width] {{2,7,6},{9,5,1},{4,3,8}}; unsigned row, col; printf ("Square:\n\n"); for (row=0; row<width; ++row) { for (col=0; col<width; ++col) { printf ("%d ", a[row][col]); } printf ("\n"); } printf ("\n"); if (is_magic((unsigned*)&a, width)) printf ("The square is magic with a magic constant of %d\n", sum_row((unsigned*)&a, 3,0)); else printf ("The square is not magic\n"); return 0; }

Related questions

Largest element in a row and largest element in a column?

To find the largest element in a row, you can iterate through the elements of that row and keep track of the largest value encountered. To find the largest element in a column, you can iterate through the elements of that column and similarly keep track of the largest value encountered. Remember to handle edge cases such as empty rows or columns.


Which element in row 6 of the peroidic table has the largest radius?

Cesium


Which element in row 8 has the largest atomic radius?

The element in row 8 (period 8) with the largest atomic radius is oganesson (Og). Oganesson is a synthetic element and is located at the bottom of the periodic table, hence it has the largest atomic radius among the elements in that row.


Which element in the row 6 of the periodic table has the largest radious?

Caesium (At no. 55).


What is the determinant of a two-by-two matrix?

To find that, you multiply the first element of the first row by the second element of the second row. You also multiply the first element of the second row with the second element of the first row. Then you subtract the products not add them.


How do you find the largest and smallest number row wise and column wise?

Use the function MAX to find the largest value. Use the function MIN to find the smallest value. If you want to find the value in a row, use the range of the cells in the row; for column, use the range of cells in the column. =MAX(A1:A12) will find the largest value in column A (from row 1 through 12). =MIN(A1:M1) will find the smallest value in row 1 (from column A through M).


What row is element helium?

it is in the first row


What element in row 6 of the periodic table has the largest atomic radius?

Cesium (Cs), atomic number 55, has the largest atomic radius in period 6.Only francium (row 7) may be larger, but testing is difficult because francium does not exist in any meaningful amounts (maybe 30 g on the entire Earth).


Where to find iron?

8th column and 4th row in the Transition Metals. Element number 26


What does the period number say about the elemnt?

It shows the horizonal row of the element so like Ex: Rb which is period 5 cause u count how many rows there is and when u find the element(He) it is in the 5th row


Which element has the most consonants in a row?

The element tungsten (W) has the most consecutive consonants in a row in its name, with six in a row (ngstn).


Where on the periodic table can you find an element that has the same chemical properties as another element but is more massive than that element?

In the same column (group) but in a row below the chemical you start with.