Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <math.h>
  6. #include <assert.h>
  7. #include <time.h>
  8. #include <malloc.h>
  9. #include <ctype.h>
  10.  
  11. #define COLS 5
  12.  
  13. bool isrishon(int num)
  14. {
  15. if (num == 0)
  16. return 0;
  17. else if (num == 1)
  18. return 0;
  19. for (int i = 2; i < num; i++)
  20. {
  21. if (num % i == 0)
  22. return 0;
  23. }
  24. return 1;
  25. }
  26.  
  27. int ex(int arr[][COLS], int rows, int cols,int **newarray)
  28. {
  29. int size = 0;
  30. for (int i = 0; i < rows; i++)
  31. {
  32. for (int j = 0; j < cols; j++)
  33. {
  34. if (isrishon(i + j))
  35. size++;
  36. }
  37. }
  38. (*newarray) = (int*)malloc(size * sizeof(int));
  39. size = 0;
  40. for (int i = 0; i < rows; i++)
  41. {
  42. for (int j = 0; j < cols; j++)
  43. {
  44. if (isrishon(i + j))
  45. {
  46. (*newarray)[size] = arr[i][j];
  47. size++;
  48. }
  49. }
  50. }
  51. return size;
  52. }
  53.  
  54. void main()
  55. {
  56. int arr[][COLS] = { 23,67,89,11,55,14,12,80,98,50,24,45,21,33,19,99,15,40,18 };
  57. int *aaa;
  58. int num = ex(arr, 4, 5, &aaa);
  59. printf("%d\n", num);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement