LastName Unit3 Assignment2c

Lab Objective: In this lab, students will create a C program that contains an array structure. They will
compile and debug their program using Visual Studio 2015.
Problem Statement
Write a program that takes n number of elements from user (where, n is specified by user), stores data in
an array and calculates the average of those numbers.
Use the below program template to answer each question. The program is created by answering all the
questions hence, do not skip any question.
Programming Shell Template
Instructions
1. Using the Xendesktop, open Visual Studio 2015. Create a new project and add a new .c file to the
project. Type the programming shell template as stated up above and continue with the following
steps below. Be sure to include comments throughout your program for readability purposes.
2. (Housekeeping): Declare the following variables in your program using appropriate data type.
When selecting a data type keep in mind the type of value you want to store, i.e., int, float,
character. Also, be sure to use conventional naming standards for all variable declarations.
n //variable used to store the number of values the user wishes to average
i //counter variable to loop through each array element
num[10] //array structure to hold 10 values
sum
average
(Hint): Since sum is going to be used for adding the value, it needs to be initialized to zero.
3. (Display Prompt): Write a printf() statement to ask user for the following message.
4. (Input): Add a scanf() statement to store user input for the number of values they wish to
process.
5. (Loop structure): Create a looping structure to catch any user input that may be out of the arrays
storage range. If the user types in a value less than 0 OR greater than 10 print out a message
telling the user that they entered an invalid number. Don’t forget to prompt the user to enter a
valid number and store that value just like you did not steps 1 and 2 above.
6. (Loop structure): Now, you will write a loop structure to store the user input of values to be
averaged into each element of the array.
To begin with, your loop structure will look like this
7. (Assignment Statement): Outside of the loop you want to create an assignment statement to
compute the averages of the values stored in each array element.
8. (Output): Write a printf() statement to display the value averaging the numbers stored in the
array. Remember, the variable sum is declared outside of the loop so it can be referred/used
anywhere within the main function. Also, to display the value stored in a variable you need to
include a conversion specifier inside of the quotation marks in the printf() and the variable names
within the parentheses.
9. (Output Screen) When you execute the program, it should be similar to the following:
int n;
int i; //count
int sum = 0;
float average;
float num[10];
printf("\nEnter the number of values to be averaged (not to exceed 10):\n");
scanf("%d", &n);
while (n <= 0 || n > 10)
{
printf("You have entered an invalid number. Please try again.\n");
printf("\nEnter the number of values to be averaged (not to exceed
10):\n");
scanf("%d", &n);
}
for (i = 0; i < n; i++)
{
printf("\nPlease Enter the elements one by one:\n", i + 1);
scanf("%f", &num[i]);
sum = sum + num[i];
}
average = sum / n;
printf("\nSum of the %d Numbers = %d\n", n, sum);
printf("\nAverage of the %d Numbers = %.2f\n\n", n, average);

Place new order. It's free, fast and safe

-+
550 words

Our customers say

Customer Avatar
Jeff Curtis
USA, Student

"I'm fully satisfied with the essay I've just received. When I read it, I felt like it was exactly what I wanted to say, but couldn’t find the necessary words. Thank you!"

Customer Avatar
Ian McGregor
UK, Student

"I don’t know what I would do without your assistance! With your help, I met my deadline just in time and the work was very professional. I will be back in several days with another assignment!"

Customer Avatar
Shannon Williams
Canada, Student

"It was the perfect experience! I enjoyed working with my writer, he delivered my work on time and followed all the guidelines about the referencing and contents."

  • 5-paragraph Essay
  • Admission Essay
  • Annotated Bibliography
  • Argumentative Essay
  • Article Review
  • Assignment
  • Biography
  • Book/Movie Review
  • Business Plan
  • Case Study
  • Cause and Effect Essay
  • Classification Essay
  • Comparison Essay
  • Coursework
  • Creative Writing
  • Critical Thinking/Review
  • Deductive Essay
  • Definition Essay
  • Essay (Any Type)
  • Exploratory Essay
  • Expository Essay
  • Informal Essay
  • Literature Essay
  • Multiple Choice Question
  • Narrative Essay
  • Personal Essay
  • Persuasive Essay
  • Powerpoint Presentation
  • Reflective Writing
  • Research Essay
  • Response Essay
  • Scholarship Essay
  • Term Paper
We use cookies to provide you with the best possible experience. By using this website you are accepting the use of cookies mentioned in our Privacy Policy.