Write a program based on the following assumptions/rules:
- You have an integer array of enough size.
- When the user enters 1, the next input (integer) will be added (i.e., inserted) to the array.
- When the user enters 2, the next two inputs will be added to the array.
- When the user enters -1, the last element will be removed from the array.
- When the user enters 3, the sum of the elements in the current array will be calculated and added to the array.
- When the user enters 4, the current array will be printed and program will be terminated.
For example, for the first example,
- The program reads an integer: 1, which means that the following integer will be added to the array. So the program reads 6 and adds it into the array.
- Then it reads 2, which means that the following two integers will be added to the array. So the program reads 10 and 20 and adds them into the array.
- Then it reads -1 which means that the last element of the array will be removed. So 20 is removed.
- Then it reads 3 which means that the sum of the current array elements will be calculated and added into the array. So 6+10=16, 16 is added into the array.
- Then it reads 4 which means that the current array will be printed. So 6 10 16 will be printed on the screen.
Examples:
1 6 2 10 20 -1 3 4
|
6 10 16
|
2 5 10 2 20 30 -1 -1 3 4
|
5 10 15
|
1 5 3 3 3 4
|
5 5 10 20
|
1 2 2 20 40 3 -1 -1 4
|
2 20
|
Important issues about all exams/projects/quizzes:
- Update just Question.c file, not Question.txt.
- Make changes only between the following comments(DO NOT modify these comments or anything outside the region marked by the comments):
- // DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE
- // DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE
- If you modify these comments for any reason, you can copy/paste the initial version from Question.txt into Question.c. Note that Question.txt is not graded at all, so anything you write in Question.txt will be discarded.
- To avoid getting the 'Binary Not Found' error, SAVE and BUILD your code before RUN.
- Do not add any extra messages message for input/output such as 'Enter an integer:', 'The result is:', etc. Any additional text that appears in the output will cause you to get no points from the question.
- Input and output of your program must be just like those in the Examples table above.