fork download
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int i,sum=0,n;
  6. int a[10];
  7. float avg;
  8. cout<<"Enter how many numbers you want ";
  9. cin>>n;
  10. if (n>10)
  11. n=10;
  12. cout<<"Enter the numbers" << endl;
  13. for (i=0;i<n;i++)
  14. cin>>a[i];
  15. for (i=0;i<n;i++)
  16. {
  17. sum=sum+a[i];
  18. }
  19. avg=sum/n;
  20. cout<<"sum of array elements "<<sum << endl;
  21. cout<<"average of array elements " <<avg << endl;
  22.  
  23. int temp;
  24. for (int i =0; i<n; i++)
  25. {
  26. for (int j=i+1; j<n; j++)
  27. {
  28. if (a[i] > a[j])
  29. {
  30. temp = a[i];
  31. a[i]=a[j];
  32. a[j]=temp;
  33. }
  34. }
  35. }
  36. cout << "The numbers in ascending order are:" << endl;
  37. for (int i =0; i<n; i++)
  38. cout << a[i] << endl;
  39. return 0;
  40. }
Success #stdin #stdout 0s 3144KB
stdin
5
5 3 2 4 1
stdout
Enter how many numbers you want Enter the numbers
sum of array elements 15
average of array elements 3
The numbers in ascending order are:
1
2
3
4
5