How can I use for loop to sum some numbers for a certain time?
2 views (last 30 days)
I want to sum a set of numbers (10 numbers in the set) for a certain time (user input)
My code is
time = input('Put numbers HERE. ');
CostTotal = 0;
for n = 1:1:time
Cost = [12 21 45 50 13 11 10 77 89 100];
CostTotal = CostTotal + Cost;
What I want is, if I put 4 as input, it calculates 12+21+45+50.
Thank you for your help.