write a matlab program to find the summation of numbers greater than 5 only from 1 to 10 using for loop. in matlab

You can write a MATLAB program to find the summation of numbers greater than 5 from 1 to 10 using a for loop as follows:

main.m
sum = 0; % initialize sum variable

for num = 1:10
    if num > 5
        sum = sum + num; % sum only numbers greater than 5
    end
end

disp(sum); % display the sum
167 chars
10 lines

Explanation:

  • Create a variable sum and initialize it to 0.
  • Iterate through the numbers 1 to 10 using a for loop.
  • Check if each number is greater than 5 using an if statement.
  • If the number is greater than 5, add it to the sum variable.
  • Finally, display the value of sum.

When you run this program, it will calculate the summation of all numbers greater than 5 from 1 to 10, which in this case is 6 + 7 + 8 + 9 + 10 = 40.

gistlibby LogSnag