diff --git a/main.c b/main.c index 7607b28..4beabc5 100644 --- a/main.c +++ b/main.c @@ -9,7 +9,6 @@ /* * This is a doubly circular link-list! */ - #include #include @@ -29,12 +28,11 @@ int main(int argc, char** argv) */ struct node *root,*n,*temp,*k,*p; - float i=0, j=0, Starting_Value=0, Last_Value=0, Choosen_Value=0, Per_Value=0; - int My_Choice=0,Clock_Choice=0, flag=0; + float i=0,j=0,a=0,b=0,c=0,value=0; + int count=0,flag=0,ch=0; root=NULL; //Initializing root with NULL - printf("\n**********//// THE MAGIC BEGAINS NOW! ;) ////**********\n"); printf("\nSuppose these is a monster who kills every nth person standing in a circle\n"); printf("Suppose you can start a circle of people with any integer number you want!\n"); @@ -46,7 +44,7 @@ int main(int argc, char** argv) */ printf("So give the staring number\n"); - scanf("%f",&Starting_Value); + scanf("%f",&a); /* * Now give the end point of the Circle! @@ -54,7 +52,7 @@ int main(int argc, char** argv) printf("Now give me the last number of the circle ;)\n"); - scanf("%f",&Last_Value); + scanf("%f",&b); /* * Now in this loop node type variable containing information part and @@ -63,7 +61,7 @@ int main(int argc, char** argv) * of inputs! */ - for(i=Starting_Value; i<=Last_Value; i++) + for(i=a;i<=b;i++) { n=(struct node *)malloc(sizeof(struct node)); n->info=i; @@ -83,7 +81,6 @@ int main(int argc, char** argv) root->link2=n; n->link=root; - /* * With these statements I have made link-list circular! * So now starting node have the address of the last node! @@ -91,57 +88,59 @@ int main(int argc, char** argv) printf("Please enter the value of the nth person\n"); - scanf("%f",&Per_Value); - + scanf("%f",&value); /* * This will be the value of n (the person number to be killed) */ printf("\n"); - printf("How you want monster to kill person Clockwise (1) or"); - printf(" Anti-clockwise (2)\n <1/2>\n"); - scanf("%d",&Clock_Choice); - + printf("How you want monster to kill person..?\n"); + printf("Press: \n") + printf("1. Clockwise \n"); + printf("2. Anti-clockwise \n"); + printf("Enter your choice:\n"); + scanf("%d",&ch); /* * This will be the value which decide the loop will run Clockwise * or Anti-Clockwise */ - printf("Very good! ;) Keep it You played very well\n"); + printf("Very good! Keep it up. You played very well\n"); + printf("The game is not yet over !!\n"); printf("Now I will play a game with you\n"); - printf("Choose a position for you before getting the result\n"); - printf("Lets see I will kill you or you will be the safe person\n"); + printf("Choose a position for you in the circle \n"); + printf("Lets see I wll kill you or you will be the safe person\n"); - scanf("%d",&My_Choice); - Per_Value = Per_Value-1; - Choosen_Value = Last_Value-Starting_Value+1; + scanf("%d",&count); + value=value-1; + c=b-a+1; - if(Clock_Choice==2) + if(ch==2) { - while(Choosen_Value > Per_Value) + while(c>value) { - for(i=0; ilink2; + root=root->link2; } - p->link2 = root->link2; - root = p->link2; - Choosen_Value--; + p->link2=root->link2; + root=p->link2; + c--; } - k = root; - if(My_Choice == root->info) + k=root; + if(count==root->info) flag=1; printf("The value is %0.f\n",root->info); - root = root->link2; + root=root->link2; while(root!=k) { printf("The value is %0.f\n",root->info); - if(My_Choice==root->info) + if(count==root->info) flag=1; root=root->link2; } @@ -149,28 +148,28 @@ int main(int argc, char** argv) else { - while(Choosen_Value > Per_Value) + while(c>value) { - for(i=0; ilink; } p->link=root->link; root=p->link; - Choosen_Value--; + c--; } k=root; - if(My_Choice==root->info) + if(count==root->info) flag=1; printf("The value is %0.f\n",root->info); root=root->link; while(root!=k) { printf("The value is %0.f\n",root->info); - if(My_Choice==root->info) + if(count==root->info) flag=1; root=root->link; }