In the C programming language, you can't determine the array size from the parameter, so you have to pass it in as an extra parameter. The solution could be:
#include <stdio.h>
void swaparrayends(int arr[], int nrElements)
{
int temp = arr[0];
arr[0] = arr[nrElements - 1];
arr[nrElements - 1] = temp;
}
void main()
{
int i;
int myArray[] = { 1,2,3,4,5 };
int nrElements = sizeof(myArray) / sizeof(myArray[0]);
swaparrayends(myArray, nrElements);
for (i = 0; i < nrElements; i++)
{
printf("%d ", myArray[i]);
}
getchar();
}
In higher languages like C# it becomes much simpler:
static void Main(string[] args)
{
int[] myArray = {1, 2, 3, 4, 5};
swaparrayends(myArray);
foreach (var el in myArray)
{
Console.Write(el + " ");
}
Console.ReadLine();
}
static void swaparrayends(int[] arr)
{
int temp = arr[0];
arr[0] = arr.Last();
arr[arr.Length - 1] = temp;
}
I don't really understand the meaning of the question. Can you reply and i'll try to help...
The correct answer to this open question is the following.
Although there are no options attached we can say the following.
Do earthquakes ever happen in Malaysia?
Yes, they do. And they are very frequent and high in intensity.
For instance, the Sabah earthquake in 2015.
On June 5, 2015, the region of Malaysia was hit by a strong earthquake, 6.0 of magnitude on the Ritcher scale. The telluric movement lasted 30 seconds and caused much destruction.
Experts and scientists confirm that this had been the strongest earthquake since the one presented in 1976.