In: Computer Science
Create properly formatted script file (Initials_Final_pb_02.m) that will prompt the user to input a 1-D array of numbers (positive, negative, zero) and then use loop and conditional statement to find the number of all non-zero elements in this array and their products
Do NOT use the built-in commands such as sum, prod, length, size, … etc.
- Use proper names for input and output variables.
Use the following 3 vectors to test your function and include the results as a commented text at the end of your script file. [3 -1 0 -4 2], [10 -15 20 -15 0], [1 0 -2 5 -2 3]
Format the output using fprintf similar to the following:
There are 4 non-zero numbers and their product is 24
#source code:
a=input("Enter vector Here:");
s=1;
non_zero_cnt=0;
for i=1:length(a)
if(a(i)~=0)
non_zero_cnt=non_zero_cnt+1;
s=s*a(i);
end
end
fprintf("There are %d non-zero numbers and their product is
%d\n",non_zero_cnt,s);
#output:
#if you have any doubt or more information needed comment below..i will respond as possible as soon..thanks..