Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <malloc.h>
  4.  
  5. int main(){
  6.     int n;
  7.     printf("Input size of array: ");
  8.     scanf("%d", &n);
  9.     int* massive = (int*)malloc(sizeof(int)*n);
  10.     printf("Input elements of array: ");
  11.     int zeros = 0;
  12.     int c = 0;
  13.     for(int i = 0; i < n; ++i){
  14.         int buf;
  15.         scanf("%d", &buf);
  16.         if(!buf)
  17.             ++zeros;
  18.         else
  19.             massive[c++] = buf;
  20.     }
  21.  
  22.     for(int i = c; i < n; ++i)
  23.         massive[i] = 0;
  24.  
  25.     printf("Answers array: ");
  26.     for(int i = 0; i < n; ++i)
  27.         printf("%d ", massive[i]);
  28.     printf("\n");
  29.     getch();
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement