6.
Write a MATLAB code that determines whether a letter is VOWEL or a
CONSONANT.
Solution:
x=input('enter an alphabet ASCII code:');
if x==97||x==101||x==105||x==111||x==117||x==65||x==69||x==73||x==79||x==85
disp('it is vowel');
else
disp('it is consonant');
end
result;
enter an alphabet ASCII code:117
it is vowel
enter an alphabet ASCII code:66
it is consonant
>>
7. Write a MATLAB code that determines whether a year is Leap or not. (Avoid using
the built in [2] function leapyear).
Solution:
function [ status ] = leapyear( year )
if mod(year, 400) == 0
status = true;
elseif mod(year, 4) == 0 && mod(year, 100) ~= 0
status = true;
else
status = false;
end
end
%(for true is 1 and for false is 0)
[ status ] = leapyear( 2000 )
status =
1
>> [ status ] = leapyear( 2001 )
status =
0
>> [ status ] = leapyear( 2016 )
status =
1