ChameL1oN

Лаба5_Задача1(Вар.5)

Dec 17th, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <locale>
  4. #include <time.h>
  5. #include <iomanip>
  6.  
  7.  
  8. using namespace std;
  9.  
  10.  
  11.  
  12.  
  13. void Print_mas(int* mass, int n){ //Функция для печати матрицы
  14. int i = 0;
  15.  
  16. while (i < n){
  17. cout << setw(6) << mass[i] << " ";
  18. i++;
  19. }
  20.  
  21. cout << endl;
  22.  
  23. }
  24.  
  25. int* form_mas(int count){
  26. int* massive = new int[count];
  27. int a = 0;
  28.  
  29. while (a < count){
  30. massive[a] = rand() % 50;
  31. a++;
  32. }
  33. return massive;
  34. }
  35.  
  36. void del(int* mass, int n){
  37. int a = n-1, i = 0, j = 0, prost = 0, b;
  38. int k = 0;
  39.  
  40. for (i = 0; i<n; i++){
  41. while (a >= i){
  42. for (k = 2; (k < (abs(mass[a]) - 1)) && (prost == 0); k++){
  43. if (mass[a] % k == 0){
  44. prost = 1;
  45. j = i;
  46. }
  47. }
  48. if (prost == 0 && (abs(mass[a])>2)){
  49. for (b = a; b < n-1; b++){
  50. mass[b] = mass[b + 1];
  51. }
  52. n--;
  53. }
  54. a--;
  55. prost = 0;
  56. }
  57. a = n - 1;
  58. }
  59.  
  60. cout << endl;
  61. cout << "Матрица после обработки : " << endl;
  62. cout << endl;
  63. Print_mas(mass, n);
  64. }
  65.  
  66.  
  67. void main()
  68. {
  69. int n, m, i = 0, j = 0;
  70. setlocale(LC_ALL, "rus");
  71. cout << "Введите кол-во столбцов в двумерном массиве" << endl;
  72. cin >> n;
  73. time_t t;
  74. srand((unsigned)time(&t));
  75. int* mass = form_mas(n);
  76. cout << "Исходная матрица : " << endl;
  77. Print_mas(mass, n);
  78. del(mass, n);
  79. }
Advertisement
Add Comment
Please, Sign In to add comment