Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #include <math.h>
- #include <assert.h>
- #include <time.h>
- #include <malloc.h>
- #include <ctype.h>
- #define COLS 5
- bool isrishon(int num)
- {
- if (num == 0)
- return 0;
- else if (num == 1)
- return 0;
- for (int i = 2; i < num; i++)
- {
- if (num % i == 0)
- return 0;
- }
- return 1;
- }
- int ex(int arr[][COLS], int rows, int cols,int **newarray)
- {
- int size = 0;
- for (int i = 0; i < rows; i++)
- {
- for (int j = 0; j < cols; j++)
- {
- if (isrishon(i + j))
- size++;
- }
- }
- (*newarray) = (int*)malloc(size * sizeof(int));
- size = 0;
- for (int i = 0; i < rows; i++)
- {
- for (int j = 0; j < cols; j++)
- {
- if (isrishon(i + j))
- {
- (*newarray)[size] = arr[i][j];
- size++;
- }
- }
- }
- return size;
- }
- void main()
- {
- int arr[][COLS] = { 23,67,89,11,55,14,12,80,98,50,24,45,21,33,19,99,15,40,18 };
- int *aaa;
- int num = ex(arr, 4, 5, &aaa);
- printf("%d\n", num);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement