Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Assignment - Class #22 11/21/2017
- In this assigment you will learn about arrays in C.
- As part of this assigment you will create a program in a file called `arrays2.c`.
- When you complete the assigment you will submit `arrays2.c` by uploading it to me
- on Slack. If you do not finish today, you have until the start of class on Tuesday
- 11/28/2017 to submit it.
- Create a file called `arrays2.c` and paste in the following contents:
- ```C
- #include <stdio.h>
- int main()
- {
- int arraySize = 0;
- while (arraySize < 1)
- {
- printf("Enter array size: ");
- scanf("%d", &arraySize);
- if (arraySize < 1)
- {
- printf("Array size must be at least 1\n");
- }
- }
- int arrayOfIntegers[arraySize];
- int currentIndex = 0;
- while (currentIndex < arraySize)
- {
- arrayOfIntegers[currentIndex] = currentIndex;
- currentIndex = currentIndex + 1;
- }
- currentIndex = 0;
- while (currentIndex < arraySize)
- {
- printf("%d\n", arrayOfIntegers[currentIndex]);
- currentIndex = currentIndex + 1;
- }
- return 0;
- }
- ```
- Upload this file to the UMBC Linux Server, compile it and run it.
- Modify the program as follows:
- 1. Change the program so that the values in the array come from the user. For
- each position in the array, it should prompt the user for an integer that should
- be stored at that position.
- 2. Add a section of code after the second while loop that calculates the average
- value stored in the array and then prints the value.
- 3. Add a section of code after __Part 2__ that prints all values in the array that are
- less than the average value in the array.
Add Comment
Please, Sign In to add comment