2305903-Sumit_Experiment_1
2305903-Sumit_Experiment_1
PROBLEM STATEMENT :
Check if the number is even
CODING :
clc
clear all
close all
a=input('Enter an Integer: ');
if rem(a,2)==0
disp('Even Integer')
end
OUTPUT :
Enter an Integer: 8
Even Integer
PROBLEM STATEMENT :
Check the number is even or not
CODING :
clc
clear all
close all
a=input('Enter an Integer: ');
if rem(a,2)==0
disp('Even Integer')
end
if rem(a,2)~=0
disp('Odd Integer')
end
OUTPUT :
Enter an Integer: 5
Odd Integer
PROBLEM STATEMENT :
Compare two ages in elseif loop
CODING :
clc
1
clear all
close all
n=input('Enter your age: ');
age=25;
if n>age
disp('I am younger')
elseif n<age
disp('You are younger')
else
disp('We both are of same age')
end
OUTPUT :
Enter your age: 20
You are younger
PROBLEM STATEMENT :
Check if number is even and divisible by 7 or just an odd number.
CODING :
clc
clear all
close all
a=input('enter an integer: ');
if rem(a,2)==0
disp('Ok Even Integer')
if rem(a,7)==0
disp('An even number Divisible by 7')
else
disp('An even number not Divisible by 7')
end
else
disp('An Odd number')
end
OUTPUT :
enter an integer: 7
An Odd number
PROBLEM STATEMENT :
Program to check weather the entered number is a weekday or not.
CODING :
clc
clear all
close all
a=input('Enter a number: ');
switch a
case 1
disp('Monday')
2
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 a number: 4
Thursday
PROBLEM STATEMENT :
Evaluate the function y=x^2 where x=[0,2,4,6,8]
CODING :
x=[0,2,4,6,8];
n=length(x)
for i=1:1:n
y(i)=x(i)^2
end
OUTPUT :
n=5
y=0
y=0 4
y = 0 4 16
y = 0 4 16 36
y = 0 4 16 36 64
PROBLEM STATEMENT :
Find all powers of 2 below 100
CODING :
v=1;n=1;i=1;
while v<100
v=[v,i]
v=2^i
i=i+1
end
OUTPUT :
3
v=1 1
v=2
i=2
v=2 2
v=4
i=3
v=4 3
v=8
i=4
v=8 4
v = 16
PROBLEM STATEMENT :
Print all prime numbers between 1 to 100
CODING :
disp("Prime Numbers are : ")
for i=2:100
for j=2:100
if(~mod(i,j))
break;
end
end
if (j>(i/j))
fprintf('%d , ',i);
end
end
OUTPUT :
Prime Numbers are :
2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71 , 73 ,
79 , 83 , 89 , 97 ,
CONCLUSION :
The experiment demonstrated the effective use of MATLAB for solving logical and
mathematical problems, enhancing programming skills and understanding of key
constructs like conditions, loops, and computations.