Write a program that inputs ten values into an array. It finds out the average value of the array and displays the values of array which are greater than the average value of array.
So let’s Write Code:
Let’s build logic First:
Algorithm for code:
- Step 1: Start
- Step 2: Declare an array and variables avg, i, and s.
- Step 3: initialize s = 0;
- Step 4: Take inputs from user.
- Step 5: Add value and divided by 10 until (i<=9)
- Step 6: Print result.
- Step 7: Program end.
Write a program that inputs ten values into an array. It finds out the average value of the array and displays the Result.
#include<iostream>
using namespace std;
main()
{
int arr[10], avg, i, s = 0;
for(i=0; i<=9; i++)
{
cout<<"Enter value no. "<<i+1<<" ? ";
cin>>arr[i];
s = s + arr[i];
}
avg = s/10;
cout<<"Values of array that are greater than averages value :"<<avg<<endl;
for(i = 0; i<=9; i++)
{
if(arr[i]>avg)
cout<<arr[i]<<endl;
}
}
Hope You will learn Something. Happy Coding.
Visit my YouTube Channel as Well😇 https://www.youtube.com/watch?v=JuIHQ9cLSEw&list=PLbIhkHxfUIItTdcyCb34uRIrPJbXBndIl&index=4
Click on the below Links for more Programming Exercises:
Conditional Structure Exercises: 👉https://myustaadg.com/category/programming-exercises/conditional-structures-exercises/
Array Exercises: 👉https://myustaadg.com/category/programming-exercises/arrays-exercises/