answersLogoWhite

0


Best Answer

Sample code is as follows:

#include <stdio.h>

void main()

{

int i = 0;

int final_number = 0;

int array[] = {-2,-6,2,4,1,6,8,20,-55};

for(i = 0; i < (sizeof(array)/sizeof(array[0])); i++)

{

if(array[i] > array[i + 1])

final_number = array[i];

}

printf("%d", final_number);

}

Tried in MinGw:

Output: 20

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you read one dimensional array of integers for highest integer?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What does a 2 dimensional array do?

A two dimensional array is a one-dimensional array of one-dimensional arrays. That is, just as we can have an array of integers, we can also have an array of integer arrays. This idea can be extended such that we can have an array of two-dimensional arrays (a three-dimensional array), and so on. We typically use a two-dimensional array to represent a table of rows and columns, where each row is a one-dimensional array.


How will you initialize a 2-d array?

All arrays are one-dimensional. A two-dimensional array is simply a one-dimensional array of one-dimensional arrays: int a[2][3]; This is an array of 2 elements where each element is itself an array of 3 integers. In other words it is an array of 6 integers. The two dimensions simply allow us to split the array into two sub-arrays of 3 elements each.


Differentiate single dimensional array to double dimensional array?

A single dimensional array is an array of items. A two-dimensional array is an array of arrays of items.


How are three dimensional arrays represented in memory Explain how address of an element is calculated in three dimensional array?

Assuming the array is mapped in contiguous memory, the memory block is divided into equal blocks according to the first dimension, and each of those blocks is divided equally according to the second dimension. The smallest blocks therefore represent a one-dimensional array according to the final dimension. To look at it another way, a three-dimensional array is a one-dimensional array where every element is a two-dimensional array. And every two-dimensional array is a one-dimensional array where every element is also a one-dimensional array. This concept can also be extended to four-dimensional arrays and beyond (a four-dimensional array being a one-dimensional array where every element is a three-dimensional array). The address of any element in a contiguous multi-dimensional array is calculated from the type of element in the array and the element index. If we assume the following three-dimensional array has been declared: int a[3][4][5]; If we also assume that an int (integer) is a 32-bit value and a byte has 8 bits, then it can be seen there are 3*4*5*32 bits allocated to the array, which is 1920 bits in total or 240 bytes. We can also say that there are 3 arrays of 4*5 integers or, more simply, 3*4 arrays of 5 integers. An array of 5 integers therefore consumes 5*32 bits, which is 160 bits or 20 bytes. The second dimension tells us there are 4 such arrays, which makes 80 bytes, and the third dimension tells us there are 3 of those, which brings us to 240 bytes. Thus to locate any element, we multiply the last index by 4 (the size of an integer), the middle index by 20 (the size of 5 integers) and the first index by 80 (the size of 20 integers), and add these three results together to obtain the offset from the start of the array. Thus element a[2][3][4] will be found (2*80)+(3*20)+(4*4) bytes from the start of the array, which is 160+60+16 or 236 bytes. This is the address of the last integer in the array, which is fortunate because a[2][3][4] is also the index of the last integer in the array (remember that array indices are zero-based). The name of the array is also a reference to the start address of the array, thus the start address is a, which is the same as saying the address of element a[0][0][0], which is at offset (0*80)+(0*20)+(0*4), which is obviously 0 bytes from a. As well as accessing elements by their indices, we can also point at individual elements using pointer arithmetic. Element a[1][2][3] can therefore be found at memory address a+(1*80)+(2*20)+(3*4), which is a+132 bytes. In point of fact, the index notation is simply syntactic sugar for the pointer arithmetic that is actually done behind the scenes. So much for arrays allocated in contiguous memory. Although there will be few occasions where 240 bytes cannot be allocated easily in contiguous memory, imagine a larger array of integers, say [128][256][512], which is 226 bytes or 64MB. On a 32-bit system, 64MB of contiguous RAM may not be available, so we must split the array into smaller arrays. This is where imagining multi-dimensional arrays as being one-dimensional arrays of one-dimensional arrays comes in handy. If we treat the first two dimensions as a two-dimensional array of integer pointers (each of which is 32-bits), then we only need 128*256*4 bytes, which is only 131,072 bytes or 128kB. Each pointer will reference a separate one-dimensional array of 512 integers, each of which is only 2kB in size (512*4). Although total memory consumption is now 256MB, because the allocation is split into one 128kB allocation and 512 separate 2kB allocations there's a far greater chance the allocation will succeed than if we attempt to allocate 64MB contiguously. The index notation hasn't actually changed but the underlying pointer arithmetic has. If we assume the pointer array is p[128][256], then referencing p[64][128][256] will return the 257th element of the array pointed to by p[64][128]. This works because the first two dimensions return a pointer to a one-dimensional array of integers. If we suppose that the pointer is x, then the final dimension returns the integer stored at x[256]. The underlying arithmetic is a little cumbersome, but can be broken down as x = (p+(64*(256*4))+(128*4)) + (256*4), which reduces to x = (p+66048) + 1024. Thus the memory address stored at offset 66048 bytes within the pointer array plus the offset 1024 returns the 257th element of the appropriate one-dimensional array of integers.


Difference between integer array and character array?

Arrays are basic structures wherein one or more elements exist "side by side" and are of the same "type". An "integer" array is an array whose elements are all of an integer type which has no fractional component. A "character" array is an array which contains nothing but character types. A "floating point" array contains elements that have both an integer and fractional portion. Simply put, they are arrays of particular types.

Related questions

What does a 2 dimensional array do?

A two dimensional array is a one-dimensional array of one-dimensional arrays. That is, just as we can have an array of integers, we can also have an array of integer arrays. This idea can be extended such that we can have an array of two-dimensional arrays (a three-dimensional array), and so on. We typically use a two-dimensional array to represent a table of rows and columns, where each row is a one-dimensional array.


How will you initialize a 2-d array?

All arrays are one-dimensional. A two-dimensional array is simply a one-dimensional array of one-dimensional arrays: int a[2][3]; This is an array of 2 elements where each element is itself an array of 3 integers. In other words it is an array of 6 integers. The two dimensions simply allow us to split the array into two sub-arrays of 3 elements each.


What is the difference between a numericial array and an associative array?

A numericial array is an array with keys made up of only integers. An associative array is an array with keys made up of anything that is not an integer. In some languages, it is possible to mix integer keys and non-integer keys into a mixed array.


Differentiate single dimensional array to double dimensional array?

A single dimensional array is an array of items. A two-dimensional array is an array of arrays of items.


What will be the algorithm to input n integers and output the largest one?

var largest : integer largest = array[0] for n : integer in array if n &gt; largest largest = n endif endfor return largest


How are three dimensional arrays represented in memory Explain how address of an element is calculated in three dimensional array?

Assuming the array is mapped in contiguous memory, the memory block is divided into equal blocks according to the first dimension, and each of those blocks is divided equally according to the second dimension. The smallest blocks therefore represent a one-dimensional array according to the final dimension. To look at it another way, a three-dimensional array is a one-dimensional array where every element is a two-dimensional array. And every two-dimensional array is a one-dimensional array where every element is also a one-dimensional array. This concept can also be extended to four-dimensional arrays and beyond (a four-dimensional array being a one-dimensional array where every element is a three-dimensional array). The address of any element in a contiguous multi-dimensional array is calculated from the type of element in the array and the element index. If we assume the following three-dimensional array has been declared: int a[3][4][5]; If we also assume that an int (integer) is a 32-bit value and a byte has 8 bits, then it can be seen there are 3*4*5*32 bits allocated to the array, which is 1920 bits in total or 240 bytes. We can also say that there are 3 arrays of 4*5 integers or, more simply, 3*4 arrays of 5 integers. An array of 5 integers therefore consumes 5*32 bits, which is 160 bits or 20 bytes. The second dimension tells us there are 4 such arrays, which makes 80 bytes, and the third dimension tells us there are 3 of those, which brings us to 240 bytes. Thus to locate any element, we multiply the last index by 4 (the size of an integer), the middle index by 20 (the size of 5 integers) and the first index by 80 (the size of 20 integers), and add these three results together to obtain the offset from the start of the array. Thus element a[2][3][4] will be found (2*80)+(3*20)+(4*4) bytes from the start of the array, which is 160+60+16 or 236 bytes. This is the address of the last integer in the array, which is fortunate because a[2][3][4] is also the index of the last integer in the array (remember that array indices are zero-based). The name of the array is also a reference to the start address of the array, thus the start address is a, which is the same as saying the address of element a[0][0][0], which is at offset (0*80)+(0*20)+(0*4), which is obviously 0 bytes from a. As well as accessing elements by their indices, we can also point at individual elements using pointer arithmetic. Element a[1][2][3] can therefore be found at memory address a+(1*80)+(2*20)+(3*4), which is a+132 bytes. In point of fact, the index notation is simply syntactic sugar for the pointer arithmetic that is actually done behind the scenes. So much for arrays allocated in contiguous memory. Although there will be few occasions where 240 bytes cannot be allocated easily in contiguous memory, imagine a larger array of integers, say [128][256][512], which is 226 bytes or 64MB. On a 32-bit system, 64MB of contiguous RAM may not be available, so we must split the array into smaller arrays. This is where imagining multi-dimensional arrays as being one-dimensional arrays of one-dimensional arrays comes in handy. If we treat the first two dimensions as a two-dimensional array of integer pointers (each of which is 32-bits), then we only need 128*256*4 bytes, which is only 131,072 bytes or 128kB. Each pointer will reference a separate one-dimensional array of 512 integers, each of which is only 2kB in size (512*4). Although total memory consumption is now 256MB, because the allocation is split into one 128kB allocation and 512 separate 2kB allocations there's a far greater chance the allocation will succeed than if we attempt to allocate 64MB contiguously. The index notation hasn't actually changed but the underlying pointer arithmetic has. If we assume the pointer array is p[128][256], then referencing p[64][128][256] will return the 257th element of the array pointed to by p[64][128]. This works because the first two dimensions return a pointer to a one-dimensional array of integers. If we suppose that the pointer is x, then the final dimension returns the integer stored at x[256]. The underlying arithmetic is a little cumbersome, but can be broken down as x = (p+(64*(256*4))+(128*4)) + (256*4), which reduces to x = (p+66048) + 1024. Thus the memory address stored at offset 66048 bytes within the pointer array plus the offset 1024 returns the 257th element of the appropriate one-dimensional array of integers.


Difference between integer array and character array?

Arrays are basic structures wherein one or more elements exist "side by side" and are of the same "type". An "integer" array is an array whose elements are all of an integer type which has no fractional component. A "character" array is an array which contains nothing but character types. A "floating point" array contains elements that have both an integer and fractional portion. Simply put, they are arrays of particular types.


Dope vector method for one dimentional array?

Dope Vector Method is use for one dimensional array and also two-dimensional array for one dimensional array we use MA(i)=sa+(i-1)*w MA is Memory Address Sa = Start Address i is subscript W for integer w=2 float=4 char=1 for two dimensional array MA(i,j)=SA{n(i-1)+(j-1)}*W


How does two dimensional array differ from single dimensional array?

A one dimensional array is a scalar value repeated one or more times.A two dimensional array is an array of one dimensional arrays.A three dimensional array is an array of two dimensional arrays, and so forth.The one dimensional array is like a list of things, where the two dimensional array is like an array of things. (Think one row of a spreadsheet versus the whole spreadsheet.)[addendum]Every level of array depth is also a level of pointer depth. For example: A 3 dimensional int array is an int***. So a one dimensional int array is an int*, and a two dimensional int array is an int**. This is only important if you are doing pointer work, but it can become very important.


What is a multi array?

A two-dimensional array is the simplest multi-dimensional array and is implemented as a one-dimensional array where every element is itself a one-dimensional array. We can imagine a two-dimensional array as being a table of rows and columns where every row is an array in its own right. A three-dimensional array is simply a one-dimensional array of two-dimensional arrays, which can be imagined as being an array of tables. Extending the concept, a four-dimensional array is a table of tables. Multi-dimensional arrays may be jagged. That is, a two-dimensional array may have rows of unequal length. Unlike regular arrays, jagged arrays cannot be allocated in contiguous memory. Instead, we use the outer array (the first dimension) to store pointers to the inner arrays. An array of strings (character arrays) is an example of a two-dimensional jagged array.


Can you modify the bubble sort algorithm to search to sort an array of characters instead of array of integers?

The bubble sort algorithm can be applied to an array of characters. Every character can be translated to an integer equivalent via the ascii table


Explain the Different types of array?

one dementional array and two dementional array