Guest User

Untitled

a guest
Nov 23rd, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. # Assignment - Class #22 11/21/2017
  2.  
  3. In this assigment you will learn about arrays in C.
  4.  
  5. As part of this assigment you will create a program in a file called `arrays2.c`.
  6. When you complete the assigment you will submit `arrays2.c` by uploading it to me
  7. on Slack. If you do not finish today, you have until the start of class on Tuesday
  8. 11/28/2017 to submit it.
  9.  
  10. Create a file called `arrays2.c` and paste in the following contents:
  11.  
  12. ```C
  13. #include <stdio.h>
  14.  
  15. int main()
  16. {
  17. int arraySize = 0;
  18. while (arraySize < 1)
  19. {
  20. printf("Enter array size: ");
  21. scanf("%d", &arraySize);
  22. if (arraySize < 1)
  23. {
  24. printf("Array size must be at least 1\n");
  25. }
  26. }
  27.  
  28. int arrayOfIntegers[arraySize];
  29.  
  30. int currentIndex = 0;
  31. while (currentIndex < arraySize)
  32. {
  33. arrayOfIntegers[currentIndex] = currentIndex;
  34. currentIndex = currentIndex + 1;
  35. }
  36.  
  37. currentIndex = 0;
  38. while (currentIndex < arraySize)
  39. {
  40. printf("%d\n", arrayOfIntegers[currentIndex]);
  41. currentIndex = currentIndex + 1;
  42. }
  43.  
  44. return 0;
  45. }
  46. ```
  47.  
  48. Upload this file to the UMBC Linux Server, compile it and run it.
  49.  
  50. Modify the program as follows:
  51.  
  52. 1. Change the program so that the values in the array come from the user. For
  53. each position in the array, it should prompt the user for an integer that should
  54. be stored at that position.
  55.  
  56. 2. Add a section of code after the second while loop that calculates the average
  57. value stored in the array and then prints the value.
  58.  
  59. 3. Add a section of code after __Part 2__ that prints all values in the array that are
  60. less than the average value in the array.
Add Comment
Please, Sign In to add comment