Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Lab Task 1:

i) write a function “sum m_to_n” using for loop that calculate the sum of
integers from m to n prompted by user. Display it as: m=5, n=8, Result is
5+6+7+8=26. You cannot use built in function “sum”.
ii) write a function “min_max_val” to find the minimum & maximum value in a
vector prompted by user. You can only use “if” & “for”. Output should be as:
“The minimum so far is the x element in the vector & maximum is y element in
the vector”, where x & y are the index of minimum and maximum value
respectively.
NOTE: you can’t use built in function “min” or “max”
Lab Task 2:
i) Use “Nested loops” to create a multiplication table of the form given
below. You can’t use built in function “multtable”.

ii) In task(i) of 1 you got the sum of integers, now


Write a function to calculate the row sums & return a
vector like this
12 26
Take a matrix 4x4
Lab Task 3:
1) Write a function “Comparison” that compares each element in vector “v” to
a number “n” to see whether it is greater than n or not?? Both vector v as
well as n should be prompted from user. Numbers greater than n should be
stored in separate vector “Gtn” & should be displayed. You are bounded to
use loops. Don’t use built in function “find”.
2)
i) Use table 5.1 from manual to compare
Vec1 & vec2. Also apply “loops” to do the same
ii) Now use built in function “all” & “isequal” to do the same and compare
with results of task 2(i). Find OR as well as AND of vec1 and vec2

You might also like