find the summation of numbers greater than 5 only from 1 to 10 using for loop. the printed output must be as shown below. the numbers are 6 7 8 9 10 in matlab

You can use a for loop in MATLAB to find the summation of numbers greater than 5 from 1 to 10. Here's how you can do it:

main.m
% Initialize the variable for summation
sum = 0;

% Iterate through the numbers from 1 to 10
for i = 1:10
    % Check if the number is greater than 5
    if i > 5
        % Add the number to the summation
        sum = sum + i;
        
        % Print the number
        disp(i);
    end
end

% Print the total summation
disp('The total summation is:');
disp(sum);
366 chars
19 lines

The above code will output:

main.m
6
7
8
9
10
The total summation is:
40
38 chars
8 lines

In this example, the for loop iterates through the numbers from 1 to 10. Each number is checked if it's greater than 5, and if so, it is added to the variable sum. The numbers greater than 5 (6, 7, 8, 9, 10) are also printed individually, and at the end, the total summation is printed.

related categories

gistlibby LogSnag