SORTING ARRAY OF 0 AND 1 WITH ONE LOOP example in C


source code:

#include <stdio.h>

int main(int argc, char **argv)
{
   
    int a[]={1,1,1,1,0,0,0,0,1,1};  
      int j=0,i; 
      for(i=0;i<10;i++) 
      { 
           if(a[i]==0) 
           { 
             a[i]=1; 
            a[j++]=0;                
           } 
      } 
     for(i=0;i<10;i++)
      printf("%d\n",a[i]);
    return 0;
}

Post a Comment

0 Comments