fork download
  1. #include <stdio.h>
  2. #include <malloc.h>
  3. #include <locale.h>
  4. int **a;
  5.  
  6. int simple(int n)
  7. {
  8. int i;
  9. for(i=2;i<= n/2;i++)
  10. if( (n%i)==0 )
  11. {
  12. return 0; //не простое число
  13. }
  14. return 1; // простое число
  15. }
  16.  
  17. int downsimple(int k, int m)
  18. {
  19. int current;
  20. // находим первое простое число
  21. for (current=0; current<m && !simple(a[k][current]); current++)
  22. ;
  23. for (int i=current+1; i<m; i++)
  24. if (simple(a[k][i])) // не простое число игнорируем
  25. if (a[k][i] > a[k][current])
  26. return 0; // следующее больше текущего - ошибка
  27. else
  28. current = i; // изменяем текущее
  29. return 1; // вернет 1 если простых чисел нет вовсе.
  30. }
  31.  
  32. int RepeatTwo(int k, int m)
  33. {
  34. int value,i;
  35. int tempmas[m];
  36.  
  37. for(i=0; i<m; i++)
  38. {
  39. tempmas[i] = a[k][i];
  40. }
  41.  
  42. for(i=0; i<m; i++)
  43. {
  44. value = tempmas[i];
  45. tempmas[i] = 0;
  46. for(int j = 0; j< m; j++)
  47. {
  48. if(value == a[k][j])
  49. {
  50. tempmas[i]++;
  51. printf("repeat: %d \n", tempmas[i]);
  52. }
  53. }
  54. }
  55. for( i=0; i<m; i++)
  56. {
  57. if(tempmas[i] < 2 && !simple(tempmas[i]))
  58. {return 0;} //число встречается 1 раз
  59. }
  60. return 1; //число встречается 2 раза и более
  61. }
  62. void matrix(int n,int m)
  63. {
  64. int i;
  65. for(i=0; i<n; i++)
  66. {
  67. printf("RepeatTwo = %d, DownSimple = %d\n",RepeatTwo(i,m) == 1 ,downsimple(i,m));
  68. if(RepeatTwo(i,m) == 1 && downsimple(i,m) == 1)
  69. {
  70. printf("Delete this str\n");
  71. free(a[i]);
  72.  
  73. }
  74.  
  75. }
  76.  
  77. }
  78.  
  79. int main()
  80. {
  81. int n,m,i,j;
  82.  
  83. printf("The NUMBER of N:\n");
  84. scanf("%d", &n);
  85.  
  86.  
  87. printf("The NUMBER of M:\n");
  88. scanf("%d", &m);
  89. a = (int**)malloc(n*sizeof(int*));
  90. for(i=0; i<n; i++)
  91. {
  92. a[i] = (int*)malloc(m*sizeof(int));
  93. for(j=0; j<m; j++)
  94. {
  95. printf("a[%d][%d] = ", i, j);
  96. scanf("%d", &a[i][j]);
  97. }
  98. }
  99.  
  100.  
  101.  
  102. matrix(n,m);
  103.  
  104.  
  105. printf("\n\nPrint result matrix:\n");
  106. for(i=0; i<n; i++)
  107. {
  108. for(j=0; j<m; j++)
  109. {
  110. printf("%5d ", a[i][j]);
  111. }
  112. printf("\n");
  113. free(a[i]);
  114. }
  115.  
  116.  
  117.  
  118. free(a);
  119. printf("\n\nMemory free!\n");
  120. return 0;
  121. }
  122.  
  123.  
Runtime error #stdin #stdout #stderr 0s 2252KB
stdin
2
5
17
13
4
4
4
1
2
3
4
5
stdout
The NUMBER of N:
The NUMBER of M:
a[0][0] = a[0][1] = a[0][2] = a[0][3] = a[0][4] = a[1][0] = a[1][1] = a[1][2] = a[1][3] = a[1][4] = repeat: 1 
repeat: 1 
repeat: 1 
repeat: 2 
repeat: 3 
repeat: 1 
repeat: 2 
repeat: 3 
repeat: 1 
repeat: 2 
repeat: 3 
RepeatTwo = 1, DownSimple = 1
repeat: 1 
repeat: 1 
repeat: 1 
repeat: 2 
repeat: 3 
repeat: 1 
repeat: 2 
repeat: 3 
repeat: 1 
repeat: 2 
repeat: 3 
Delete this str
repeat: 1 
repeat: 1 
repeat: 1 
repeat: 1 
repeat: 1 
RepeatTwo = 1, DownSimple = 0
repeat: 1 
repeat: 1 
repeat: 1 
repeat: 1 
repeat: 1 


Print result matrix:
    0    13     4     4     4 
stderr
*** Error in `./prog': double free or corruption (fasttop): 0x09661018 ***