Saturday, March 16, 2013

number guesser program in c.

    Guess a number  sequence using the limit  (1,6) ,the program will guess the number within  8 steps
you must provide(input)  1. how many terms are in the exact position (first input)
                                         2.how many terms are misplaced (second input)

 try example 1443(i am guessing this..)
guesser output     chooser output
1111                      1   0
2221                      0    1
3313                      1    1
4143                       2    2
1443                       4     0


got it......!!!!


#include<conio.h>                // number guesser program in c.
#include<process.h>
#include<stdio.h>
#include<stdlib.h>
void main()
{
int i,j,n=2,r,p=2,q,t=4,a[4]={1,1,1,1},c,d,k=3,z,m=0;
clrscr();
z=a[k];
while(1)
{
for(i=0;i<4;i++)
{
printf("%d",a[i]);
}
scanf("%d",&c);
scanf("%d",&d);
if(c==4)
{
printf("Got it !!!\n");            
break;
}
else  if((c==0)&&(d==0))
 {
 printf("hai 1\n");
 for(i=m;i<t;i++)
  {
  a[i]=p;
  }
  p++;
 }


 else if((c+d)==1)
 {
   printf("hai 3\n");
for(i=m;i<t;i++)
  {
  a[i]=p;
  }
  p++;a[k]=z;k--;
  if(k==0)                                   
  {
  m++;
  }
}
else if((c==1)&&(d==1))
 {
   printf("hai 4\n");
   t--;
  for(i=m;i<t;i++)
  {
  a[i]=p;

  }
  p++;

  a[k]=z;
  k--;                                                 
  if(k==0)
  {
  m++;
  }
 }

 else  if((c==1)&&(d==2))
 {
   printf("hai 5\n");
   t--;
for(i=m;i<t;i++)
  {
  a[i]=p;
  }
  p++;a[k]=z;k--;
  if(k==0)
  {
  m++;
  }
 }
  else  if((c+d)==3)
 {
   printf("hai 10\n");
   t--;
for(i=m;i<t;i++)
  {
  a[i]=p;
  }
  p++;a[k]=z;k--;
  if(k==0)
  {
  m++;
  }
 }

 else  if((c==2)&&(d==2))
 {
   printf("hai 6\n");
   t=t-2;
for(i=0;i<t;i++)
  {
  r=a[i];
  a[i]=a[i+1];
a[i+1]=r;

  }

 }
 else  if((c+d)==4)
 {
   printf("hai 8\n");
   t=t-2;
for(i=0;i<t;i++)
  {
  r=a[i];
  a[i]=a[i+1];
a[i+1]=r;

  }

 }




}

getch();
}

No comments:

Post a Comment