Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <math.h>
  5. using namespace std;
  6. const int N=5;
  7.  
  8. int fact(int n)
  9. {
  10. int p=1;
  11. while (n>1)
  12. {
  13. p*=n;
  14. n--;
  15. }
  16. return p;
  17. }
  18.  
  19. void zero_7(int a[N][N])
  20. {
  21. for (int j=0; j<N; j++)
  22. {
  23. int k=0;
  24. for (int i=0; i<N; i++)
  25. {
  26. if (a[i][j]%7==0)
  27. {
  28. k++;
  29. }
  30. }
  31. if (k>0)
  32. {
  33. for (int i=0; i<N; i++)
  34. a[i][j]=0;
  35. }
  36. }
  37. }
  38. int main()
  39. {
  40. setlocale(0,"Rus");
  41.  
  42. //задача 4
  43. int mass[N][N];
  44. cout<<"начальный массив: "<<endl;
  45. for (int i=0; i<N; i++)
  46. {
  47. for (int j=0; j<N; j++)
  48. {
  49. mass[i][j]=rand()%8;
  50. cout<<setw(3)<<mass[i][j];
  51. }
  52. cout<<endl;
  53. }
  54. zero_7(mass);
  55. cout<<"конечный массив: "<<endl;
  56. for (int i=0; i<N; i++)
  57. {
  58. for (int j=0; j<N; j++)
  59. {
  60. cout<<setw(3)<<mass[i][j];
  61. }
  62. cout<<endl;
  63. }
  64.  
  65. //задача 3
  66. double sum=1;
  67. double x;
  68. cout<<"Введите x"<<endl;
  69. cin>>x;
  70. int n;
  71. cout<<"Сколько слагаемых должно быть в ряде"<<endl;
  72. cin>>n;
  73. cout<<sum;
  74. double pr=x;
  75. for (int i=2; i<=n; i++)
  76. {
  77. pr*=x;
  78. if (i%2==0)
  79. {
  80. cout<<" - "<<pr<<"/"<<fact(i);
  81. sum-=(pr/fact(i));
  82. }
  83. else
  84. {
  85. cout<<" + "<<pr<<"/"<<fact(i);
  86. sum+=(pr/fact(i));
  87. }
  88. }
  89. cout<<endl<<"sum="<<floor(sum*1000)/1000<<endl;
  90.  
  91. //задача 5
  92. cout<<"Введите числа. После введения 0 ввод закончится"<<endl;
  93. int chislo, k=0;
  94. double summ=0;
  95. bool dat=0;
  96. while (dat!=1)
  97. {
  98. cin>>chislo;
  99. if (chislo % 2 == 1)
  100. {
  101. k++;
  102. summ+=chislo;
  103. }
  104. dat = (chislo == 0);
  105. }
  106. if (k == 0) cout<<"В последовательности нет нечетных чисел"<<endl;
  107. else cout<<"Среднее арифм нечетных: "<<summ/k;
  108. system("pause");
  109. return 0;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement