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

Lab-3

The document is a MATLAB report by Priya Gupta detailing various programming exercises that utilize conditional statements, loops, and switch cases. It includes code snippets for calculating the roots of a quadratic equation, determining the day of the week based on input, performing operations on two variables, calculating factorials, summing elements of an array, and summing student marks. Each section contains the code, input prompts, and expected outputs.

Uploaded by

Priya Gupta
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)
4 views

Lab-3

The document is a MATLAB report by Priya Gupta detailing various programming exercises that utilize conditional statements, loops, and switch cases. It includes code snippets for calculating the roots of a quadratic equation, determining the day of the week based on input, performing operations on two variables, calculating factorials, summing elements of an array, and summing student marks. Each section contains the code, input prompts, and expected outputs.

Uploaded by

Priya Gupta
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/ 6

MATLAB – REPORT

Priya Gupta Date: 12.07.2024


23EE035 (ECE-3rd)
Lab-3

Aim: Use of conditional statements such as if else, for and while loop and
using switch case.
Software Used: MATLAB R2023b
Function / Command Used: Mathematical Operations, if elseif else, switch
case, for and while.

Programme (Code):

Ques 1
clc;
clear all;
a = input("enter coefficients of x^2")
b = input("enter the coeffieient of x")
c = input("enter the value of c")

D = b^2-4*a*c

if D>0
disp("roots are real")
elseif D==0
disp("roots are real and equal")
else
disp("roots are imaginary")
end

x_1=(-b+sqrt(D))/2*a
x_2=(-b-sqrt(D))/2*a

disp(x_1)
disp(x_2)

Output-
Ques-2
clc;
clear all;

dayNumber =input("enter day number: ")

switch dayNumber
case 1
disp("sunday")
case 2
disp("monday")
case 3
disp("tuesday")
case 4
disp("wednesday")
case 5
disp("thursday")
case 6
disp("friday")
case 7
disp("saturday")

otherwise
disp("invalid input. Enter no. between 1 and 7")
end

Output-

Ques –3
clc;

clear all;
x = input("enter first variable: ")
y = input("enter the second variable: ")

if x>=0 & y>=0


funct_1 = x+y
disp(funct_1)
elseif x>=0 & y<0
funct_2 = x+y*y
disp(funct_2)
elseif x<0 & y>=0
funct_3 = x*x+y
disp(funct_3)
else x<0 & y<0
funct_4 = x*x+y*y
disp(funct_4)

end

Output-
Ques 4
clc;
clear all;

n = input("Enter the no.")


factorialResult=1;

for variable = 1:n


factorialResult = factorialResult * variable;
end
disp("factorialResult");
disp(factorialResult);

Output-
Ques 5
clc;
clear all;

n = input("enter the no. of elements: ")

array = zeros(1,n);

sum_of_elements = 0;

for i = 1:n
array(i) = input("enter elements:");
sum_of_elements = sum_of_elements + array(i);
end
disp("The array is: ")
disp(array)
disp("Sum of elements of array is: ")
disp(sum_of_elements)

Output-
Ques-6
clc;
clear all;
n = input("enter the no. of students: ")
marks = zeros(1,10)

sum_of_marks = 0;
i = 1;

while i<=10
marks(i) = input("enter marks:")
sum_of_marks = sum_of_marks + marks(i);
i = i + 1;
end
disp("The marks is: ");
disp(marks);
disp("Sum of marks is: ");
disp(sum_of_marks);

Output-

You might also like