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:
#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:
-
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.
-
Add a section of code after the second while loop that calculates the average value stored in the array and then prints the value.
-
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.