Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "StdAfx.h"
- #include <stdio.h>
- #include <malloc.h>
- #include <stdlib.h>
- int main()
- {
- int *a, *b;
- int i, n, j = 0, s = 0;
- printf("Enter the size : ");
- scanf_s("%d", &n);
- a = (int*)malloc(n * sizeof(int));
- for (i = 0; i < n; i++)
- {
- printf("a[%d] = ", i);
- scanf_s("%d", &a[i]);
- }
- for (i = 0; i < n; i++)
- {
- if (a[i] != 0) {
- a[j] = a[i];
- j++;
- }
- }
- a = (int*)realloc(a, j * sizeof(int));
- b = (int*)malloc(j * sizeof(int));
- for (i = 0; i < j; i++) {
- if (a[i] < 0) {
- b[s] = a[i];
- s++;
- }
- }
- b = (int*)realloc(b, s * sizeof(int));
- n = 0;
- for (i = 0; i < j; i++){
- if (a[i] > 0){
- a[n] = a[i];
- n++;
- }
- }
- a = (int*)realloc(a, n * sizeof(int));
- printf("Положительные\n");
- for (i = 0; i < n; i++){
- printf("a[%d] = %d ", i, a[i]);
- }
- printf("\nОтрицательные\n");
- for (i = 0; i < s; i++){
- printf("b[%d] = %d ", i, b[i]);
- }
- free(a);
- free(b);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement