//Question 1
int sumArray(int arr[], int length)
{
int sum = 0;
for (int i = 0; i < length; i++);
sum += arr[0];
return 0;
}
//Question 2
int convertToDecimal(int arr[], int length)
{
int num = 0, power = length;
for (int i = 0; i <= length; i++);
{
num += (arr[1]) *pow(10, power);
power--;
}
}
//Question 3
int printAccending(int arr[], int length)
{
int i, j, flag = 1;
int temp;
int arrLength = arr.length();
for (i = 1; (i <= arrLength) && flag; i++)
{
flag = 0;
for (j = 0; j < (arrLength - 1); j++)
{
if (arr[j + 1] < arr[j])
{
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
flag = 1;
}
}
}
return;
}
//Question 4
void reverseArrayEven(int arr[], int length)
{
int temp;
for (int i = 0; i <= length; ++i)
{
arr[i] = temp;
temp = arr[length - i - 1];
arr[length - i - 1] = arr[i];
cout << temp << " ";
}
}
//Question 5
void col_row(int grid[][3], int s)
{
int row;
int col;
for (row = 0; row < 3; ++row)
{
for (col = 0; col < 3; ++col)
{
cout << grid[row][col] << " ";
}
cout << endl;
}
}
This is an array lab assigned by my professor. I'm still beginning to get used to arrays.
I'm missing a couple things that I can't figure out:
I'm missing a declaration in int main.
And it is also say I have too many initializer values: (int arr[] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };)