fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main( )
  4. {
  5. int arr[10]={1,-5,63,78,3,4,-35,6,0,8} , Positive=0, notpositive=0, i;
  6. int *arrPositive, *arrnotpositive;
  7.  
  8. for (i=0; i<10; i++){
  9. if (arr[i]>0)
  10. Positive++;
  11. }
  12. notpositive = 10 - Positive;
  13.  
  14. arrPositive = (int *)malloc (Positive* sizeof(int));
  15. arrnotpositive = (int *)malloc (notpositive* sizeof(int));
  16. Positive = 0;
  17. notpositive=0;
  18.  
  19. for (i=0; i<10; i++){
  20. if (arr[i]>0)
  21. {
  22. arrPositive[Positive] = arr[i];
  23. Positive++;
  24. }
  25. else
  26. {
  27. arrnotpositive[notpositive] = arr[i];
  28. notpositive++;
  29. }
  30. }
  31. printf ("original array:\n ");
  32. for (i=0; i<10; i++)
  33. printf ("%d ", arr[i]);
  34. printf ("\n");
  35.  
  36. printf ("Positive array: ");
  37. for (i=0; i<Positive; i++)
  38. printf ("%d ", arrPositive[i]);
  39. printf ("\n");
  40.  
  41. printf ("arrnotpositive array: ");
  42. for (i=0; i<notpositive; i++)
  43. printf ("%d ", arrnotpositive[i]);
  44. printf ("\n");
  45.  
  46. free (arrPositive);
  47. free (arrnotpositive);
  48. return 0;
  49. }
  50.  
  51.  
Success #stdin #stdout 0s 4448KB
stdin
Standard input is empty
stdout
original array:
 1 -5 63 78 3 4 -35 6 0 8 
Positive array: 1 63 78 3 4 6 8 
arrnotpositive array: -5 -35 0