Question

Write a program using loop and array that asks users to input 10 numbers, then calculates...

Write a program using loop and array that asks users to input 10 numbers, then calculates the average of those numbers. (In C++)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
using namespace std;

int main() {
   int arr[10],sum=0;
   float avg;
   cout<<"Enter 10 numbers : ";
   for(int i=0;i<10;i++)
   cin>>arr[i];
   for(int i=0;i<10;i++)
   sum=sum+arr[i];
   avg=(float)sum/10;
   cout<<"Average : "<<avg;
   return 0;
}

OUTPUT:-

// If any doubt please comment

Add a comment
Answer #2

Following is the c++ program that takes as input from user 10 numbers and calculates the average:

Approach:

  • Declare the essential header.
  • Inside the main define an array of size 10 and declare the variables.
  • Using for loop to take input from user 10 numbers and save these numbers in the array named the array. Along with this also add these numbers in the sum variable.
  • Divide the value of sum by 10 to calculate average.
  • Finally, print the value of the average.

Step 2:

Code:

#include <iostream>//header file

using namespace std;//setting up name space

//start of main

int main() {

   //declare necessary variables

   int sum=0,array[10];

   float avg;

   //for loop to take input from user in array and also add these numbers

   for(int i=0;i<10;i++)

   {

     //prompt user to input the numbers of array

     cout<<"Enter number "<<i+1<<" :";

     cin>>array[i];

     //adding elements of arary

     sum=sum+array[i];

   }

   //calculate the average

   avg=(float)sum/10;

   //print average of array

   cout<<"Average of 10 numbers is : "<<avg;

   return 0;

}

Output:

The output of the above program is given below:

Add a comment
Know the answer?
Add Answer to:
Write a program using loop and array that asks users to input 10 numbers, then calculates...
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
  • write a program code that asks the user how many numbers they wish to find the...

    write a program code that asks the user how many numbers they wish to find the statistics of and then asks the user to enter those numbers. The program must then calculate and display the average variance and standard deviation of the numbers entered by the user. the program code must -ask three user how many numbers they wish to find the statistics of -ask the user to enter those numbers and store them in an array - use a...

  • In java, write a program that gets 10 integer numbers from the user using user input,...

    In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read.   Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. version1:  use a while loop. version2:  use a do-while loop. version 3:  use a for loop. For each version, use a loop to input 10 int numbers from the user...

  • C++ 4. Write a program that inputs 5 scores using a do while loop and asks...

    C++ 4. Write a program that inputs 5 scores using a do while loop and asks a user whether to continue or not ("yes" or "no il pressed you continues if pressed no' terutiinales) then calculates the average. 5. Make a program calculates sales for its division and quarterly earnings and show the total sum. Use 5 by 2 array matrix 6. This is an extra credil questioni Produce a program that displays by decreasing or decremeniting by 4 starting...

  • P.2. Division Write a C program to input an integer n. Then the program asks users...

    P.2. Division Write a C program to input an integer n. Then the program asks users to input n integers. Calculate the sum of all non negative integers and the division of this with every negative integer in the sequence. p3 Write a C program to print all 3-digit abc numbers, satisfying: (a+b+c)=(a.b.c). Example: 3-digit 123 number fulfills requirement as (1+2+3)=1.2.3

  • Write a program that asks the user to input 10 integers of an array. The program...

    Write a program that asks the user to input 10 integers of an array. The program then inserts a new value at position (or index) given by the user, shifting each element right and dropping off the last element. For example, in the sample input/output below, the program will insert the value 30 at index 3. All the previous numbers of the array starting from position 3 (i.e., 7 1 20 9 23 8 22 will be shifted one position...

  • Write a C++ program by using array with the size 10. The user will input the...

    Write a C++ program by using array with the size 10. The user will input the number between 0 to -10. Then, calculate and display by how many numbers in the array within the range -9 to -2.

  • (C programing, Not C++) Write a program in C that asks the user to input 10...

    (C programing, Not C++) Write a program in C that asks the user to input 10 numbers. Store these numbers in an array. Then ask the user to input a single number. Your program should execute a linear search on the array, trying to find that number. If the number exists in the array, have the program print out which position/element the number was found at. If the target number is not in the array, have the program print out...

  • In C++: Write a program that asks the user for an array of X numbers. Your...

    In C++: Write a program that asks the user for an array of X numbers. Your program moves the largest number all the way to the right, and then shows it to the user. Hint: Use a loop to swap X times, but only swap if the number on the left is bigger than the number on the right. Sample Run: How many numbers would you like to enter? 6 Please enter number 1: 10 Please enter number 2: 8...

  • 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 Python program that asks users to input an integer number and print the summation...

    Write a Python program that asks users to input an integer number and print the summation of its digits and total number of its digits. (i.e., for n=35, sum is 3+5=8, and total number of digits is 2).

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