Question

QUESTION 16 assume you have n of integer numbers in array A. write general iterative algorithm to calculate the average of n
0 0
Add a comment Improve this question Transcribed image text
Answer #1

General iterative algorithm to calculate AVERAGE of n numbers from an array

1. Start

2. Initialize an array of size N and AVERAGE

3. Initialize TOTAL=0

4. Input the elements of the array by using for loop : for(i=0;i<N;i++)

5. Calculate the total of all elements in array : TOTAL=TOTAL+array[i]

6. end the for loop

7. print TOTAL

8. Calculate the average of all elements in array : AVERAGE=TOTAL/N;

9. print AVERAGE

10. stop

======================================================

C program to calculate AVERAGE of n numbers from an array :

#include <stdio.h>

int main()

{

    int n, i;

    float Array_Number[100], TOTAL = 0.0, AVERAGE;

    printf("Enter the how many number of elements you want in array : ");

    scanf("%d", &n);

    for (i = 0; i < n; ++i)

{

        printf("%d. Enter Array_Number: ", i + 1);

        scanf("%f", &Array_Number[i]);

        TOTAL += Array_Number[i];

    }

    AVERAGE = TOTAL / n;

    printf("Average = %.2f", AVERAGE);

    return 0;

}

=====================================================

Output :

Enter the how many number of elements you want in array :  3                                                                  

1. Enter Array_Number: 8                                                                                                      

2. Enter Array_Number: 4                                                                                                      

3. Enter Array_Number: 3                                                                                                      

Average = 5.00

========================================================

Add a comment
Know the answer?
Add Answer to:
QUESTION 16 assume you have n of integer numbers in array A. write general iterative algorithm...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Here is the 16-bit, unsigned binary representation of 4100: 0001 0000 0000 0100 Write the 16-bit,...

    Here is the 16-bit, unsigned binary representation of 4100: 0001 0000 0000 0100 Write the 16-bit, unsigned binary representation of 2050. TT T Arial + 3(12pt) * T - 12 i 52 Path: P Words:0 QUESTION 8 What are the largest and smallest numbers that you can represent using the 9-bit, 2's complement representation scheme? Write both the bit strings and the equivalent decimals.

  • QUESTION 16 Explain the purpose and application of binary systems. T E T TT Arial 3...

    QUESTION 16 Explain the purpose and application of binary systems. T E T TT Arial 3 (12pt) Path: p Click Save and Submit to sae and submit. Click Save All Answers to save all answers. QUESTION 16 Explain the purpose and application of binary systems. T E T TT Arial 3 (12pt) Path: p Click Save and Submit to sae and submit. Click Save All Answers to save all answers.

  • Write an algorithm that takes an array B and a number N as inputs. Suppose that...

    Write an algorithm that takes an array B and a number N as inputs. Suppose that the array B contains n distinct numbers. Compute the sum of the N largest numbers in the array B. Example: if the array B= [4, 5, 8, 11, 3] and N = 3, then the algorithm should return 24 (11+8+5).

  • Question 7 10 points Save Answer What can you say about the convergence or divergence of...

    Question 7 10 points Save Answer What can you say about the convergence or divergence of the following series? If you use a test to answer this question, make sure you mention the name of the test. Type your answer in the space provided and explain the reason to your answer. 1 Σ n=1 sin(n) ABC TT T Arial 4 3 (12pt) T III Path: p Words:0

  • Part I Short Answer (50 points) 1. Write a pseudocode declaration for a String array initialized...

    Part I Short Answer (50 points) 1. Write a pseudocode declaration for a String array initialized with the following strings: “Einstein”, “Newton”, “Copernicus”, and “Kepler”. 2. Assume names in an Integer array with 20 elements. Write a pseudocode algorithm a For Loop that displays each element of the array. 3. Assume the arrays numberArray1 and numberArray2 each have 100 elements. Write a pseudocode algorithm that copies the values in numberArray1 to numberArray2 . 4. Write a pseudocode algorithm for a...

  • Question 13 10 points Save Answer Why does $100 in the future not have the same...

    Question 13 10 points Save Answer Why does $100 in the future not have the same value as $100 today? T TT T- E- Arial 3 (12pt) Path: p Words:0 Click Submit to complete this assessment. Question 13 of 13 « Save and Submit JUN W P W 14 Question 13 10 points Save Answer Why does $100 in the future not have the same value as $100 today? T TT T- E- Arial 3 (12pt) Path: p Words:0 Click...

  • Consider an ordered array A of size n and the following ternary search algorithm for finding...

    Consider an ordered array A of size n and the following ternary search algorithm for finding the index i such that A[i] = K. Divide the array into three parts. If A[n/3] > K. the first third of the array is searched recursively, else if A[2n/3] > K then the middle part of the array is searched recursively, else the last thud of the array is searched recursively. Provisions are also made in the algorithm to return n/3 if A[n/3]...

  • Write a Java program with a single-dimension array that holds 11 integer numbers and sort the...

    Write a Java program with a single-dimension array that holds 11 integer numbers and sort the array using a bubble sort. Next, identify the median value of the 11 integers. Here are the steps your program must accomplish. algorithm (either flowchart or pseudocode) that you will use to write the program Step 1. Create an Place the algorithm in a Word document. 6. Ste the Step 2. Code the program in Eclipse and ensure the following steps are accomplished. 1....

  • C++ C++ Write a program to input eight integer numbers into an array named grade. As...

    C++ C++ Write a program to input eight integer numbers into an array named grade. As each number is input, add the number into a total. After all numbers are input, display the numbers and their average. (You can use cin to take number or use rand() to assign random numbers to the array.)

  • Write a program that first reads an integer for the array size, then reads numbers into...

    Write a program that first reads an integer for the array size, then reads numbers into the array, computes their average, and finds out how many numbers are above the average. Make sure to include pointer syntax. Example output: Enter array size: 10 10 random numbers between 1 and 10 generated are: 2 8 5 1 10 5 9 9 3 5 The average is: 5.7 Number of items above the average = 4 C++ Code only.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT