Advertisement
LabiinfaCibGyti

laba10+11.13

Jan 16th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <math.h>
  4. using namespace std;
  5. double func(int a[5][5])
  6. {
  7. int i, j;
  8. double p = 0;
  9. for (i = 0; i < 5; i++)
  10. {
  11. for (j = 0; j < 5; j++)
  12. {
  13. if (a[i][j]%5==0)
  14. p++;
  15. }
  16. }
  17. return (p);
  18. }
  19. void func2(int a[5][5])
  20. {
  21. int i, j;
  22. for (i = 0; i < 5; i++)
  23. {
  24. for (j = 0; j < 5; j++)
  25. {
  26. if (a[i][j]%2==0)
  27. a[i][j]=0;
  28. }
  29. }
  30. }
  31. int main()
  32. {
  33. int i, j, a[5][5];
  34. setlocale(LC_ALL, "");
  35. for (i = 0; i < 5; i++)
  36. {
  37. for (j = 0; j < 5; j++)
  38. {
  39. a[i][j] = -10 + rand() % 20;
  40. }
  41. }
  42. cout << "Матрица 1" << endl;
  43. for (i = 0; i < 5; i++)
  44. {
  45. for (j = 0; j < 5; j++)
  46. {
  47. cout << a[i][j] << "\t";
  48. }
  49. cout << endl;
  50. }
  51. cout << endl;
  52. cout << "Кол-во элементов кратных 5 = " << func(a) << endl;
  53. cout << endl;
  54. func2(a);
  55. cout << "Матрица 2" << endl;
  56. for (i = 0; i < 5; i++)
  57. {
  58. for (j = 0; j < 5; j++)
  59. {
  60. cout << a[i][j] << "\t";
  61. }
  62. cout << endl;
  63. }
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement