Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4. using namespace std;
  5. int main()
  6. {
  7. const int arraySize=10;
  8. int arrayName[arraySize];
  9. cout<<"Please enter 10 integers. "<<endl;
  10. for(int i=0; i<arraySize; ++i)
  11. {
  12. cout<<"["<<i+1<<"]";
  13. cin>>arrayName[i];
  14. }
  15. double sum=0;
  16. for(int i=0; i<arraySize; ++i)
  17. {
  18. sum=sum+arrayName[i];
  19. }
  20. double average = sum/arraySize;
  21. cout<<"Average is: "<<average<<endl;
  22. int counter=0;
  23. double sum_interval=0;
  24. for(int i=0; i<arraySize; ++i)
  25. {
  26. if (arrayName[i]>=-5 && arrayName[i]<=5)
  27. {
  28. sum_interval=sum_interval+arrayName[i];
  29. counter++;
  30. }
  31. }
  32. if(counter>0)
  33. {
  34. double average_interval=sum_interval/counter;
  35. cout<<"Average of elements that belongs to interval[-5,5] is: "<<average_interval<<endl;
  36. }
  37. double p,q;
  38. double sum_p_q=0;
  39. double counting=0;
  40. cout<<"Enter the beginning of interval for this array: ";
  41. cin>>p;
  42. cout<<"Enter the end of interval for this array: ";
  43. cin>>q;
  44. for (int i=0; i<arraySize; ++i)
  45. {
  46. if (arrayName[i]>=p && arrayName[i]<=q)
  47. {
  48. sum_p_q=sum_p_q+arrayName[i];
  49. counting++;
  50. }
  51. }
  52. if(counting>0)
  53. {
  54. double average_interval_p_q=sum_p_q/counting;
  55. cout<<"Average of interval between"<<"["<<fixed<<setprecision(2)<<p<<","<<fixed<<setprecision(2)<<q<<"]""is: "<<average_interval_p_q<<endl;
  56. }
  57. int sum_odd=0;
  58. for(int i=0; i<arraySize; ++i)
  59. {
  60. if(arrayName[i]%2!=0)
  61. {
  62. sum_odd=sum_odd+arrayName[i];
  63. }
  64. }
  65. cout<<"Sum of odd numbers is: "<<sum_odd<<endl;
  66. for(int i=0;i<arraySize;++i)
  67. {
  68. if (arrayName[i]%3==0)
  69. {
  70. cout<<"Value that divisible by 3: "<<arrayName[i]<<"\t"; //
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement