Given an array of integers, Move all non-zero elements to the left of all zero elements.
Implementation:
Implementation:
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #define MAX 1000 int main() { int t,size,arr[MAX],i,j,brr[MAX]; /* Get the number of test cases */ scanf("%d",&t); while(t--) { /* Get the size of the array */ scanf("%d",&size); /* Get the elements of the array */ for(i=0;i<size;i++) scanf("%d",&arr[i]); for(i=0,j=0;i<size;i++) { if(arr[i]!=0) { brr[j]=arr[i]; j++; } else continue; } for(i=j;i<size;i++) brr[i]=0; for(i=0;i<size;i++) { printf("%d",brr[i]); if(i==(size-1)) { printf("\n"); } else { printf(" "); } } } return 0; }