Assignment 2
Arrays
1. Write a function called reversit() that reverses a C-string (an array of
char). Use a for
loop that swaps the first and last characters, then the second and next-
to-last characters, and so on. The string should be passed to reversit()
as an argument.
Write a program to exercise reversit(). The program should get a string
from the user,
call reversit(), and print out the result. Use an input method that allows
embedded
blanks. Test the program with Napoleon’s famous phrase, “Able was I
ere I saw Elba.”
2. Start with a program that allows the user to input a number of
integers, and then stores them in an int array. Write a function called
maxint() that goes through the array, element by element, looking for
the largest one. The function should take as arguments the address of
the array and the number of elements in it, and return the index
number of the largest element. The program should call this function
and then display the largest element and its index number.
3. Write a C++ program that multiplies two matrices A & B of dimensions
4×4. (Look into how two 02-dimensional array are multiplied.
4. Write a C++ program that finds the inverse of a 3×3 matrix. (Look
into how the inverse of a matrix if possible calculated)
5. Write a C++ program that stores 100 integers in an array and then
bubble sort the array in ascending order. (Look into how bubble sort
is performed)
Arrays
1. Write a function called reversit() that reverses a C-string (an array of
char). Use a for
loop that swaps the first and last characters, then the second and next-
to-last characters, and so on. The string should be passed to reversit()
as an argument.
Write a program to exercise reversit(). The program should get a string
from the user,
call reversit(), and print out the result. Use an input method that allows
embedded
blanks. Test the program with Napoleon’s famous phrase, “Able was I
ere I saw Elba.”
2. Start with a program that allows the user to input a number of
integers, and then stores them in an int array. Write a function called
maxint() that goes through the array, element by element, looking for
the largest one. The function should take as arguments the address of
the array and the number of elements in it, and return the index
number of the largest element. The program should call this function
and then display the largest element and its index number.
3. Write a C++ program that multiplies two matrices A & B of dimensions
4×4. (Look into how two 02-dimensional array are multiplied.
4. Write a C++ program that finds the inverse of a 3×3 matrix. (Look
into how the inverse of a matrix if possible calculated)
5. Write a C++ program that stores 100 integers in an array and then
bubble sort the array in ascending order. (Look into how bubble sort
is performed)