#include <stdio.h>
#define childe 21

// Remove the  i-th number from the array until the array will be empty
void main(){
  int  arr[childe] ;
  int  DeadNum=2 , allZero=0 , i=1 , arrInd=1 , count=1  , loop=0;

  for(i=0;i<childe;i++) arr[i]=i;
  while (allZero<(childe-1)) {
   loop++ ;
   for(i=1;i<childe;i++){
	if (arr[i]){
	  count++ ;
	  if(count%DeadNum){
	   arr[i]=0 ;
	   allZero++ ;
	   printf("delete place : %d \n",i);
	  }
	}
   }
  }
  printf("the number of loop was : %d \n",loop) ;
}
Published in: C++
Download

Related snippets