Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move zeros to end in c #35

Merged
merged 1 commit into from
Oct 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}