Not in high school but i tried my best to help
(Sorry that its blurry )
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;
}
Answer:
6=110
13=1101
18=10010
27=11011
Explanation:
A decimal number is converted to binary number by constantly dividing the decimal number by 2 till the number becomes zero and then write the remainders in reverse order of obtaining them.Then we will get our binary number.
I will provide you 1 example:-
18/2 = 9 the remainder =0
9/2 = 4 the remainder =1
4/2 = 2 the remainder =0
2/2 = 1 the remainder =0
1/2 = 0 the remainder =1
Writing the remainder in reverse order 10010 hence it is the binary equivalent of 18.