0% found this document useful (0 votes)
8 views

2305903-Sumit_Experiment_1

The document outlines an experiment aimed at implementing MATLAB programs to solve mathematical and logical problems using conditional statements, loops, and array operations. It includes various problem statements, coding examples, and outputs demonstrating the functionality of the scripts, such as checking even/odd numbers, comparing ages, and evaluating mathematical functions. The conclusion emphasizes the enhancement of programming skills and understanding of key constructs through the experiment.

Uploaded by

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

2305903-Sumit_Experiment_1

The document outlines an experiment aimed at implementing MATLAB programs to solve mathematical and logical problems using conditional statements, loops, and array operations. It includes various problem statements, coding examples, and outputs demonstrating the functionality of the scripts, such as checking even/odd numbers, comparing ages, and evaluating mathematical functions. The conclusion emphasizes the enhancement of programming skills and understanding of key constructs through the experiment.

Uploaded by

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

EXPERIMENT 1

AIM : Implement MATLAB programs to solve mathematical and logical problems


using conditional statements, loops, and array operations.

OBJECTIVE : To develop problem-solving skills by writing MATLAB scripts for


evaluating conditions, generating sequences, and performing mathematical
computations efficiently.

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.

NAME : SUMIT MANDAL


SEC : CSE - 30
ROLL : 2305903

You might also like