Q. 93. Write a program to accept "n" numbers into array. Find the Average of n Numbers and print all numbers that are Above Average.
Copy Code:
#include <iostream>
using namespace std;
int main()
{
int a[100], n, i, sm=0, av=0 ;
cout << "How many numbers can you provide? -> ";
cin >> n;
cout << "Okay... \nEnter " << n << " numbers \n" ;
for ( i = 0 ; i < n ; ++i)
{
cin >> a [ i ] ;
sm = sm + a[ i ] ;
}
av = sm/n ;
cout << "Average is : " << av ;
cout << "\nNumbers above Average " << av << " are : \n" ;
for (i=0 ; i<n ; ++i)
{
if (a[ i ] > av)
cout << a[ i ] << " ";
}
return 0;
}
No comments:
Post a Comment