Showing posts with label Interesting. Show all posts
Showing posts with label Interesting. Show all posts

Monday, March 11, 2013

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;
}

Monday, February 21, 2011

How to Excute System Commands in C

 /* system example : DIR */  
 #include <stdio.h>  
 #include <stdlib.h>  
 int main ()  
 {  
  int i;  
  //printf ("Checking if processor is available...");  
  if (system(NULL)) puts ("Ok");  
  else exit (1);  
  printf ("Executing command dir...\n");  
  i=system ("dir"); // put ls if you are using linux  
  printf ("The value returned was: %d.\n",i);  
  return 0;  
 }