Using above concept Write a MATLAB program to enter marks of

Using above concept, Write a MATLAB program to enter marks of three subjects namely, Physics, History, and Psychology on a scale of 100. Calculate AVERAGE. If AVG is greater than or equal to 75, Display Grade as A. If AVG is greater than 50 and less than 75, Display Grade as B. If AVG is greater than 25 and less than 50, Display Grade as Otherwise, Grade is F. Write a MATLAB program using for loop to compute the sum of the squares of all integers from 2 to 20. 2^2 + 3^2 + 4^2 + ... + 20^2. Write a for loop to compute the sum of all of the odd integers from 1 to 501 (inclusive) 1^2 + 3^2 + 5^2 + ... + 501^2. Using while loop, write a MATLAB program to display all the even numbers and odd numbers between 10 to 50.

Solution

%taking marks as input using the input command and casting them into double
%type
physics = double(input(\'Physics marks: \'));
history = double(input(\'History marks: \'));
psychology = double(input(\'Psychology marks: \'));

%calculating total of marks in physics, history and psychology
total = physics + history + psychology;

%calculating average
AVG = total/3;


%conditions to check the average and grant appropriate grade
if AVG >= 75
    grade = \'A\';
elseif AVG > 50
    grade = \'B\';
elseif AVG > 25;
    grade = \'C\';
else
    grade = \'F\';
end

%displaying the grade using disp and concatenating the strings using strcat
disp(strcat(\'Grade: \', grade));


%part I.
%initialising the sum of squares to 0
sum_of_squares = 0;

%for loop to iterate through the values whose sum of squares we need to
%find
for i=2:1:20
    sum_of_squares = sum_of_squares + i*i;
end

%displaying the sum of squares
disp(strcat(\'Sum of squares from 2 to 20:   \', num2str(sum_of_squares)));

%part II.
%initialising the sum of squares to 0
sum_of_odd_squares = 0;

%for loop to iterate through the values whose sum of squares we need to
%find
for i=1:2:501
    sum_of_odd_squares = sum_of_odd_squares + i*i;
end

%displaying the sum of odd squares
disp(strcat(\'Sum of odd squares from 1 to 501:   \', num2str(sum_of_odd_squares)));

%part III.

%Printing out the even numbers from 10 to 50.

%initialising n to 10
n = 10;
while n<=50
    disp(n); %displaying n
    n = n+2;
end


%Printing out the odd numbers from 10 to 50.
%initialising n to 11
n = 11;
while n<=50
    disp(n)
    n = n+2;
end

 Using above concept, Write a MATLAB program to enter marks of three subjects namely, Physics, History, and Psychology on a scale of 100. Calculate AVERAGE. If
 Using above concept, Write a MATLAB program to enter marks of three subjects namely, Physics, History, and Psychology on a scale of 100. Calculate AVERAGE. If

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site