Skip to content

Commit

Permalink
Merge pull request Burnout-Devil#35 from LostHeart-Gaming/patch-4
Browse files Browse the repository at this point in the history
Move zeros to end in c
  • Loading branch information
Burnout-Devil committed Oct 18, 2022
2 parents 5c68b8d + 60e610c commit ae8160c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ZerostoEnd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdio.h>
void zerosToEnd(int arr[], int n)
{
int count={0};

for(int i=0;i<n;i++)
if(arr[i]!=0)
arr[count++]=arr[i];

while(count <n)
arr[count++]=0;
}

int main()
{
int arr[]=[1,2,3,4,5];
int n=sizeof(arr) / sizeof(arr[0]);
pushZerosToEnd(arr, n);
printf("%s\n", "Array after pushing all zeros to end of array:");
for (int i = 0; i < n; i++)
printf("%d ", arr[i]);
return 0;
}

0 comments on commit ae8160c

Please sign in to comment.