answersLogoWhite

0


Best Answer

int lastLargestIndex(int a[],int n) //a=array, n= number of elements in array

{

int max=a[0],maxp=0; //max=largest no., maxp= position of largest no.

for(int i=0;i<n;i++)

if(a[i]>=max)

{

max=a[i];

maxp=i;

}

return maxp;

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a C plus plus function lastLargestIndex that returns the index of the last occurrence of the largest element in the array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Design an algorithm to determine the largest element in a list?

Assume the first element is the largest and store its value. Then traverse the remainder of the list, one element at a time. If the current element's value is larger than the stored value, overwrite the stored value with the current element's value. Once you've traversed the list, the stored value will hold the largest value.


What is the function that returns the largest value in a set of values?

MAX


Ascending and descending order in HTML javascript?

You have the sort() method of Javascript arrays:---var a = [1,2,10,11];a.sort(); // gives [1, 10, 11, 2]---The default sort is lexicographic, sorting the values as strings.For numbers and descending sort, you can pass in a function:---function sortNum(a, b) {return a - b;}function sortDesc(a, b) {return b - a;}a.sort(sortNum); // gives [1, 2, 10, 11]a.sort(sortDesc); // gives [11, 10, 2, 1]---The function takes two arguments, and returns a negative number if the first element is smallest, a positive number if the first element is largest, and zero if they are equal.See related link.


Write a program in c to find the largest no out of a matrix of order mn?

/* using ellipses (...) to indicate tabs for clarity */ double largest (double *array, int M, int N) { ... int i, j; ... double *element; ... double answer = array[0][0]; ... for (i=0; i&lt;M; i++) { ... ... for (j=0; j&lt;N; j++) { ... ... ... element = array + i*M + j; ... ... ... if (*element &gt; answer) answer = *element; ... ... } ... } ... return answer; }


C program to find the largest element in a row?

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 &gt; result) result = *p; // if the current element is larger, update stored value } return result; // return largest value }

Related questions

Choose the element that is largest.?

The element that is largest on the periodic table is Oganesson, with an atomic number of 118.


What is the Program to find the largest element in an array and position occurrence?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; main() { int a[100]; int n,largest,index,position; printf("enter the number of elements in the array"); scanf("%d",&amp;n); printf("enter %d elements",n); for(index=0;index&lt;n;index++) scanf("%d",&amp;a[index]); largest=a[0]; position=0; for(index=1;index&lt;n;index++) if(a[index]&gt;largest) { largest=a[index]; position=index; } printf("largest element in the array is %d\n",largest); printf("largets element's position in the array is %d\n",position+1); getch(); }


Element named for the sixth-largest continent?

What is the element named for the sixth-largest continent?


Which is the 4th largest element found on lithosphere?

Iron, Fe, is the 4th largest element found on the lithosphere.


What is the largest organ of the human body and what is its function?

The largest human organ is the skin and it's function is to protect you.


What is the largest natural stable element?

The largest natural stable element is bismuth with atomic number 83. It is the heaviest element that is stable and does not undergo radioactive decay.


What elements has the LARGEST atom?

Element hassium has the largest Atomic Mass.


Which element has the largest radius?

francium has the largest ionic radius


Which element has largest oxidation number?

Fluorine (F) has the largest oxidation number of +7.


Which element is the largest noble gas?

Radon


45 4150 1720 75 The Element Largest Value Is?

{4/5, 41/50, 17/20, 75%} The Element Largest Value Is?


What element was named for the 1st largest continent?

The element Europium was named after the continent of Europe, the 1st largest continent in terms of land area.