You are on page 1of 9

Program 2

Aim: WAP To perform simple arithme c opera ons in


MATLAB(addi on subtrac on , mul plica on , division
and modulus)
Source code :
a=[12 44 33;76 65 25;67 23 34];
b=3;
c=a+b
d=a-b
e=a*b
f=a/b
g=mod(a,b)

Output:
Program 3
Aim: WAP To Perform bitwise opera ons in
MATLAB.
Source code :
a=28;
b=45;
c=bitand(a,b)
d=bitor(a,b)
e=bitxor(a,b)
output:
Program 4
Aim: WAP To Perform rela onal opera ons in
MATLAB.
Source code:
a=[ 34 18 15];
b=[55 18 16];
a==b
a<b
a>b
output:
Program 5
Aim: Write a program to combine looping and
branching.
Source code :
sum1 = 0;
sum2 = 0;
N = 19;
for k=1:N sum1 = sum1 + k;
if( mod(k, 2)==0 )
sum2 = sum2 + k;
end
end
sum1
sum2
Output:
Page no 7

Program 6
Aim: Write a program to implement nested for
loop.
Source code :
row=5;
cols=5;
for i=1:rows
for j=1:cols
product=i*j;
fprin (‘%d*%d=%d\t\n’,i,j,product);
end
end

Output:
Program 7
Aim: Write a program to perform branching using
if else statement.
Source code :
age = 20;
if (age >= 18)
fprin ("You are eligible to drive.\n")
else
fprin ("You are not eligible to drive.\n")
end
Output:
Program 8
Aim: WAP To Calculate area of triangle when
three sides of the triangle is given.
Source code:
a=[5 12 13];
b=[8 15 17];
c=[7 24 25];
s=(a+b+c)./2;
area=sqrt(s.*(s-a).*(s-b).*(s-c));
fprin ("the areaa in oreder are %.2f\n",area)
output:
Program 9
Aim: Write a program to calculate area of triangle
when base and height of triangle are given.
Source code :
base = 34;
height = 56;
area = (base * height) / 2
Output:
Program 10
Aim: WAP To find greatest of three numbers.
Source code:
num1 = input('Enter the Number 1: ');
num2 = input('Enter the Number 2: ');
num3 = input('Enter the Number 3: ');
if (num1 >= num2) && (num1 >= num3)
greatest = num1;
elseif (num2 >= num1) && (num2 >= num3)
greatest = num2;
else
greatest = num3;
end
fprin ('The greatest number is: %d\n', greatest);

output:

You might also like