Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int OverAvg(int A[],int n)
- {
- int B[n];
- int sum = 0;
- for(int i = 0; i<n; i++)
- {
- sum += A[i];
- }
- int avg = sum/n;
- for(int i = 0; i<n; i++)
- if(A[i] > avg) // Check if the number in 'i' position is bigger than the avg of all the numbers
- {
- B[i]=A[i]; //If yes, it will store it in the second array keeping the same index
- cout<<"B[" << i << "]= " << B[i] << " ";
- }
- cout<<endl;
- }
- int main()
- {
- int n;
- cout<<"n= ";
- cin>>n;
- int A[n], B[n];
- for(int i = 0; i<n; i++)
- {
- cout<<"Enter number " << i << " :";
- cin>>A[i]; // Storing numbers
- }
- OverAvg(A,n); // Calls OverAvg Function
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement