Advertisement

Responsive Advertisement

missnori

 #include<stdio.h>

int move(int,int);

int rmove(int,int);

int m=3,c=3,m1=0,c1=0;

main()

{

int flag=1,p,q,r,a[20],b[20],i=0,x,z,n;

printf("\nRules are:\n 1.Boat capacity = 2\n 2.entered m and c must be >=3\n 3.m and c values must also be 

less than available m and c values at river sides\n 4.m=c=0 not possible for moving boat\n 

\t\t ***********************START PLAYING********************* \n");

while(flag==1)

{

printf("\nleft side=>(%dM,%dC)///// <bo(M,C)at> ==> ///// right side=>(%dM,%dC) \n",m,c,m1,c1);

printf("Enter m and c to move from left to right\n");

scanf("%d%d",&p,&q);

r=move(p,q);

if(r==1)

{

a[i]=p;

b[i]=q;

flag=1;

i++;

if(m1==3 && c1==3)

{

printf("solution found\n\n\n\n ********************Succesful***********\n");

break;

}

}

else

{

printf("Not possible move\n \n\n\n ********************Game Over***********\n");

flag=0;

}

if(flag==1)

{

printf("\nleft side=>(%dM,%dC)///// <== <bo(M,C)at> ///// right side=>(%dM,%dC)\n",m,c,m1,c1);

printf("Enter m and c to move from right to left\n");

scanf("%d%d",&x,&z);

r=rmove(x,z);

if(r==1)

{

a[i]=x;

b[i]=z;

flag=1;

i++;

}

else

{

printf("move Not possible \n\n\n\n ********************Game Over***********\n");

flag=0;

}

}

}

n=0;

printf("Moves taken are:\n");

while(n<i)

{

printf("\\\\<(%dM,%dC)>\\\\\ \n",a[n],b[n]);

n++;

}

return 0;

}


int move(int e,int f)

{

m=m-e;

c=c-f;

m1=m1+e;

c1=c1+f;

if(m!=0 && m1!=0)

{

if(m<c||m1<c1)

return (0);

else

return (1);

}

else if(m==0 || m1==0)

return (1);

return 0;

}


int rmove(int g,int h)

{

m1=m1-g;

c1=c1-h;

m=m+g;

c=c+h;

if(m!=0&&m1!=0)

{

if(m<c||m1<c1)

return (0);

else

return (1);

}

else if(m1==0 || m==0)

return (1);

return 0;

}

missnori cpp

#include<stdio.h>

int move(int,int);

int rmove(int,int);

int m=3,c=3,m1=0,c1=0;

main()

{

int flag=1,p,q,r,a[20],b[20],i=0,x,z,n;

printf("\nRules are:\n 1.Boat capacity = 2\n 2.entered m and c must be >=3\n 3.m and c values must also be 

less than available m and c values at river sides\n 4.m=c=0 not possible for moving boat\n 

\t\t ***********************START PLAYING********************* \n");

while(flag==1)

{

printf("\nleft side=>(%dM,%dC)///// <bo(M,C)at> ==> ///// right side=>(%dM,%dC) \n",m,c,m1,c1);

printf("Enter m and c to move from left to right\n");

scanf("%d%d",&p,&q);

r=move(p,q);

if(r==1)

{

a[i]=p;

b[i]=q;

flag=1;

i++;

if(m1==3 && c1==3)

{

printf("solution found\n\n\n\n ********************Succesful***********\n");

break;

}

}

else

{

printf("Not possible move\n \n\n\n ********************Game Over***********\n");

flag=0;

}

if(flag==1)

{

printf("\nleft side=>(%dM,%dC)///// <== <bo(M,C)at> ///// right side=>(%dM,%dC)\n",m,c,m1,c1);

printf("Enter m and c to move from right to left\n");

scanf("%d%d",&x,&z);

r=rmove(x,z);

if(r==1)

{

a[i]=x;

b[i]=z;

flag=1;

i++;

}

else

{

printf("move Not possible \n\n\n\n ********************Game Over***********\n");

flag=0;

}

}

}

n=0;

printf("Moves taken are:\n");

while(n<i)

{

printf("\\\\<(%dM,%dC)>\\\\\ \n",a[n],b[n]);

n++;

}

return 0;

}


int move(int e,int f)

{

m=m-e;

c=c-f;

m1=m1+e;

c1=c1+f;

if(m!=0 && m1!=0)

{

if(m<c||m1<c1)

return (0);

else

return (1);

}

else if(m==0 || m1==0)

return (1);

return 0;

}


int rmove(int g,int h)

{

m1=m1-g;

c1=c1-h;

m=m+g;

c=c+h;

if(m!=0&&m1!=0)

{

if(m<c||m1<c1)

return (0);

else

return (1);

}

else if(m1==0 || m==0)

return (1);

return 0;

}

tower of hanoi

#include "stdio.h"


void towers(int,char,char,char);


void towers(int n,char frompeg,char topeg,char auxpeg)

 { /* If only 1 disk, make the move and return */

   if(n==1)

     { printf("\nMove disk 1 from peg %c to peg %c",frompeg,topeg);

       return;

     }

   /* Move top n-1 disks from A to B, using C as auxiliary */

   towers(n-1,frompeg,auxpeg,topeg);

   /* Move remaining disks from A to C */

   printf("\nMove disk %d from peg %c to peg %c",n,frompeg,topeg);

   /* Move n-1 disks from B to C using A as auxiliary */

   towers(n-1,auxpeg,topeg,frompeg);

 }

main()

 { int n;

   printf("Enter the number of disks : ");

   scanf("%d",&n);

   printf("The Tower of Hanoi involves the moves :\n\n");

   towers(n,'A','C','B');

   return 0;

 }

hanoi

#include "stdio.h"

void towers(int,char,char,char);

void towers(int n,char frompeg,char topeg,char auxpeg)
 { /* If only 1 disk, make the move and return */
   if(n==1)
     { printf("\nMove disk 1 from peg %c to peg %c",frompeg,topeg);
       return;
     }
   /* Move top n-1 disks from A to B, using C as auxiliary */
   towers(n-1,frompeg,auxpeg,topeg);
   /* Move remaining disks from A to C */
   printf("\nMove disk %d from peg %c to peg %c",n,frompeg,topeg);
   /* Move n-1 disks from B to C using A as auxiliary */
   towers(n-1,auxpeg,topeg,frompeg);
 }
main()
 { int n;
   printf("Enter the number of disks : ");
   scanf("%d",&n);
   printf("The Tower of Hanoi involves the moves :\n\n");
   towers(n,'A','C','B');
   return 0;
 }

Post a Comment

0 Comments