Advertisement
MDGTutorials

Untitled

Jun 9th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int OverAvg(int A[],int n)
  5. {
  6. int B[n];
  7. int sum = 0;
  8. for(int i = 0; i<n; i++)
  9. {
  10. sum += A[i];
  11. }
  12. int avg = sum/n;
  13. for(int i = 0; i<n; i++)
  14. if(A[i] > avg) // Check if the number in 'i' position is bigger than the avg of all the numbers
  15. {
  16. B[i]=A[i]; //If yes, it will store it in the second array keeping the same index
  17. cout<<"B[" << i << "]= " << B[i] << " ";
  18. }
  19. cout<<endl;
  20. }
  21.  
  22. int main()
  23. {
  24. int n;
  25. cout<<"n= ";
  26. cin>>n;
  27. int A[n], B[n];
  28.  
  29. for(int i = 0; i<n; i++)
  30. {
  31. cout<<"Enter number " << i << " :";
  32. cin>>A[i]; // Storing numbers
  33. }
  34. OverAvg(A,n); // Calls OverAvg Function
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement