Professional Documents
Culture Documents
Untitled
Untitled
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”
Code:
a)
b)
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”.
b)
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
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
Code:
a)
b)i)
b)ii)