3. write a matlab program to find the summation of numbers greater than 5 only from 1 to 10 using while loop. (hint: if statement and break statement is nested). in matlab

Here's a MATLAB program that uses a while loop, if statement, and break statement to find the summation of numbers greater than 5 from 1 to 10:

main.m
% Initialize variables
n = 1;
sum = 0;

% Start the loop
while n <= 10
    % Check if the current number is greater than 5
    if n > 5
        % Add the number to the sum
        sum = sum + n;
    end
    
    % Increment the loop counter
    n = n + 1;
end

% Display the final sum
disp("The summation of numbers greater than 5 from 1 to 10 is:");
disp(sum);
362 chars
20 lines

This program will output:

main.m
The summation of numbers greater than 5 from 1 to 10 is:
40
60 chars
3 lines

The program checks if the current number is greater than 5 using the if statement. If the condition is true, the number is added to the sum. The while loop continues until the counter n reaches 10. The break statement is not needed in this case because the loop will naturally terminate when n exceeds 10.

gistlibby LogSnag