Lab03 - Types and arrays

Arrays and pointers

  • No checking of the out-of-bound indexing
  • Fixed size known at the compile time

int arr[10];

int n = 5;
char vars[n];

float coeffs[] = {4.2, 0.12, 8.7773};

  • Arrays are passed to functions as pointers

Task 1: Static arrays

Write a program which will calculate the dot product of two vectors (arrays). Each array should contain 3 elements. You should code the values for one of the elements, and prompt the user at run-time for the values of the second. When you have this in place, THEN alter your code to make use of a function which takes two arrays, and returns the dot product.

Task 1b: Functions

Create a separate function in your code to calculate the dot product. You should use pointers inside your function.

Task 2: Matrix Multiplication

Using your existing code as a base, ask the user for 9 numbers. Construct a 2D array (3×3) to store these in.

Calculating the resulting matrix from multiplying this 2D array with the other vector.

courses/be5b99cpl/labs/lab03.txt · Last modified: 2023/10/09 19:05 by brouggeo