36.6k views
0 votes
Question 6 Code Style The code below contains several program

style problems. Correct the style. s = input('numbers?: '); numbers
= []; for i = 1:s v = input('number: '); n = [n, v]; end

1 Answer

4 votes

Step-by-step explanation:

Here is the corrected code:

```

s = input('How many numbers? ');

numbers = [];

for i = 1:s

v = input('Enter a number: ');

numbers = [numbers, v];

end

```

Changes made:

- Added a space after the colon in the input prompt to improve readability.

- Added a space after the semicolon in the first line to improve readability.

- Added a space before and after the equal sign in the for loop to improve consistency.

- Changed "n" to "numbers" in the line that adds the input value to the list to improve clarity.

- Added a space after the comma in the line that adds the input value to the list to improve readability.

User DarkMath
by
8.0k points

No related questions found