Problem 5) Write a program that asks the user to input a vector of integers. The
ID: 2291887 • Letter: P
Question
Problem 5) Write a program that asks the user to input a vector of integers. The program then counts the number of elements, the number of positive elements, the number of positive elements divisible by three, and the number of elements divisible by six. The program displays the results as: The vector has XX elements. XX elements are positive, among those XX are divisible by three, and XX are divisible by six." Here XX stands for the corresponding number of elements. For the data needed for this problem, a) ask the user to enter a vector of integer numbers. The user will enter the following data 3 -4 5 12 -9 1 -19 9 -5-17 13 8 -7 18-19 -3 5 11 12 - 13 0 -2 6 b) Use the data stored in the file vecIntegeres.mat. This file has been uploaded to the class BeachBoard.Explanation / Answer
Matlab Script:
%use X = load('vecIntegers.mat') to work on part b
% for part a
X = input('Enter vector of integers');
%remaining script is same for both parts
numele = length(X);
numpos = sum(X>=0);
numdivby3 = length(X(find(rem(X,3)==0)));
numdivby6 = length(X(find(rem(X,6)==0)));
fprintf('The vector has %d elements. %d elements are positive, among those %d are divisible by three, and %d are divisible by six ',numele,numpos,numdivby3,numdivby6);
command window output: