Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. void shiftZeros(int arr[],int n);
  4. int main(){
  5.  
  6. int *arr;
  7. int size;
  8. printf("Enter the size of array: \n");
  9. scanf("%d", &size);
  10. arr = (int*)malloc(size * sizeof(int));
  11. size = sizeof(arr) / sizeof(arr[0]);
  12. shiftZeros(arr,size);
  13. printf("Array after pushing all zeros to the end of it: \n");
  14. for(int i = 0;i<size;i++){
  15. printf("\n", arr[i]);
  16. }
  17. return 0;
  18. }
  19.  
  20. void shiftZeros(int arr[],int n){
  21. int count = 0;
  22. int i;
  23.  
  24. for(i=0;i<n;i++){
  25.  
  26. if(arr[i] != 0){
  27. arr[count++] = arr[i];
  28. }
  29.  
  30. while(count < n){
  31. arr[count++] = 0;
  32. }
  33.  
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement