If have the code mostly right but I keep getting the error b

If have the code mostly right but I keep getting the error below. I don\'t know solve the problem without using division or division like functions.

Part 2: Divisible by 11 Write a MATLAB function named isDiv11 to receive a number as input, and determine if it is divisible by 11. The output argument is a logical-1 (true) if the number is divisible by 11 and 0 (false) if it is not. Example: >>isDiv11 (92) ans >>isDiv11 (7480) ans Code Requirements: No division is allowed! Instead determine if the number is divisible by 11 using this rule: Take the alternating sum of the digits in the number, reading from left to right. If that is divisible by 11, so is the original number. So, for instance, 2728 has alternating sum of digits 2-7+2-8 =-11. The number 91818181818, which has an alternating sum of 44, is also divisible by 11. Additionally, if the alternating sum is zero, it is divisible by 11 No MATLAB functions that can be used to determine divisibility (such as rem) are permitted No vectorization is allowed! Do not use any functions, such as sum, any, or find, that work on an entire array. This includes use of the colon operator (except in a for loop) *****Violation of these requirements will result in a grade of zero for this part of the Input Restrictions The function should halt and return a red error message for the following conditions. Any input is nonscalar Any input is not a positive integer Any input is greater than or equal to 1x1015 * Hint Built-in functions num2str and str2num will be useful to get to the individual digits of the input number. They are discussed in Chapter 7 of your book, and in MATLAB help

Solution

function TF=isDiv11(x)
if x<0
error(\'Input is not a positive integer\');
end
if length(x)>1
error(\'Input is not scalar\');
end
T=~ mod(x,1);
if T==0
error(\'Input must be an integer\');
end
if x>=1000000000000000
error(\'Input is greater or equal to 1*10^15\');
end
A=num2str(x);
s=0;
for i=1:length(A)
s=s+(-1)^(i+1)*str2num(A(i));
end
n=s/11;

if n==fix(n)
TF=1;
else
TF=0;
end
end

Output:

>> isDiv11(34)
ans =
0
>> isDiv11(92)
ans =
0
>> isDiv11(7480)
ans =
1
>>

If have the code mostly right but I keep getting the error below. I don\'t know solve the problem without using division or division like functions. Part 2: Div

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site