0% found this document useful (0 votes)
94 views2 pages

Lab5 ReadMe PDF

This document outlines exercises for an introduction to programming lab session. It includes: 1) Completing previous session exercises and writing a function to check if a string is a substring of another. 2) Writing header and implementation files for vector functions to read, print, calculate length and dot product of vectors. 3) Creating and printing a 3D array. 4) Demonstrating passing addresses between variables. 5) Swapping values of two variables. 6) Additional optional exercises including reversing a portion of an array, computing the nth Fibonacci number, and removing spaces from a string.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
94 views2 pages

Lab5 ReadMe PDF

This document outlines exercises for an introduction to programming lab session. It includes: 1) Completing previous session exercises and writing a function to check if a string is a substring of another. 2) Writing header and implementation files for vector functions to read, print, calculate length and dot product of vectors. 3) Creating and printing a 3D array. 4) Demonstrating passing addresses between variables. 5) Swapping values of two variables. 6) Additional optional exercises including reversing a portion of an array, computing the nth Fibonacci number, and removing spaces from a string.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

Lab Five

ID1303: Introduction to Programming

1. Complete exercises from previous sessions.


2. Add the following function declaration to myString.h (code shared), write its definition
in myString.c and test this function.
int isSubstring(char string1[],char string2[]);
If string1 is a substring of string2, then the function should return the first index
(position) of string1 in string2; otherwise it should return -1. For example, if string1
is STA and string2 is CRYSTAL, then the function should return 3.
3. Write a header file called vector.h with the following declarations.
void vectorRead(float num[],unsigned int dimension);
void vectorPrint(int num[],unsigned int dimension);
float vectorLength(float num[], unsigned int dimension);
float vectorDotProduct(float num1[],num2[],unsigned int dimension);
(a) You can guess what these functions should do; write their definitions in a file called
vector.c.
(b) Create an object file from vector.c.
(c) Test these functions with a file called vectorTest.c and compile it along with vec-
tor.o.
(d) Create a makefile for vectorTest.c (see makefile2). To run the makefile, simply
type make in your terminal. The makefile is executed from ”bottom-up”. The lines
above each command indicate the target and source files.
4. Create a 3D array (of any type) size 2 × 3 × 4 and print the addresses of all the array
elements.
5. Create an integer variable num and two variables ptr1 and ptr2, both containing the
address of num. Use ptr1 to change the value of num and display the value using ptr2.

The remaining programs are optional. Try as many as you can.


6. Write a program that accepts values in two integer variables and swaps their values.
7. Write a function with the following declaration.

1
void reverseArray(int num[],int left, int right);
The function should reverse the elements of the array passed to it in the range
[lef t, lef t + 1, . . . , right].
For example, if the array is {1, 2, 3, 4, 5, 6, 7}, calling reverseArray(num,2,4) will yield
the array {1, 2, 5, 4, 3, 6, 7}.
8. Write a recursive function to compute the nth Fibonacci number.
9. Write a function that accepts an input string (including spaces) and then removes
all the spaces. For example, if the input is ”One two three”, the output should be
”Onetwothree”.

You might also like