0% found this document useful (0 votes)
2 views4 pages

Assignment 1 (2)

The document outlines four MATLAB programming assignments aimed at checking various conditions: whether a number is even or odd, comparing ages, determining if a number is even or divisible by 7, and identifying the day of the week based on an integer input. Each assignment includes a problem statement, aim, MATLAB code, and example output. The programs utilize conditional statements and user input to produce results.

Uploaded by

Avipsa Basu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Assignment 1 (2)

The document outlines four MATLAB programming assignments aimed at checking various conditions: whether a number is even or odd, comparing ages, determining if a number is even or divisible by 7, and identifying the day of the week based on an integer input. Each assignment includes a problem statement, aim, MATLAB code, and example output. The programs utilize conditional statements and user input to produce results.

Uploaded by

Avipsa Basu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

ASSIGNMENT 1

1)Problem statement: Write a program in MATLAB to check if a number is even or


odd

AIM: To test whether a number is even or odd

clc

clear all

close all

a=input('Enter an integer:')

if rem (a,2)==0 %rem=Remainder after division.

disp ('Even integer')

end

OUTPUT

Enter an integer

14

Even integer

2)Problem statement: Write a program in MATLAB to check if someone is older or


younger or the same age using if..else..else if

AIM: To test whether someone is same age or older or younger than a certain age

clc

clear all
close all

n = input ('What is your age: ')

age = 25;

if n > age

disp('i am younger')
elseif n < age
disp('you are younger')

else

disp('we are of same age')

end

OUTPUT

What is your age

34

You are older

3)Problem statement: Write a program in MATLAB to check if a number is even or


divisible by 7

AIM: To test whether if a number is even or divisible by 7

clc

clear all

close all

a=input ('Enter an integer:')

if rem (a,2)==0
disp (‘Ok ,Even integer’)

if rem (n,7)==0

disp (‘An Even number Divisible by 7 ’)

else

disp (‘An Even number but not Divisible by 7 ’)

end

else

disp (‘Odd number’)

end

OUTPUT
Enter an integer
21

Odd number

4)Problem statement: Write a program in MATLAB to check what day of the week it
is

AIM: To the day of the week

clc

clear all

close all

a=input ('Enter an integer:')

switch a

case 1

disp('Monday')

case 2

disp('Tuesday')

case 3
disp('Wednesday')

case 4

disp('Thursday')

case 5

disp('Friday')

case 6

disp('Saturday')

case 7

disp('Sunday')

otherwise
disp('not a weekday')
end

OUTPUT

Enter an integer

Sunday

You might also like