Two errors:
- The function should not have n as an argument. Wait to ask the user
- don't use "sum" as a variable name; it's a function
- if you want to do "sum=sum+x" it needs to be in the loop and x needs to be a scalar. But, there's no reason to do it like that since you're already storing the results in an array. Just do this:
mysum = sum(x);
- if you've calculated the sum, why are you printing x(i)?