mazimazi
چهارشنبه 06 خرداد 1388, 02:07 صبح
با سلام به دوستان عزیز این برنامه 10 اسم از ورودی می گیره و بعد یه اسم دیگه می گیره و میگه هست یا نیست ولی مشکل داره چه باشه چه نباشه میگه نیست کسی می دونه مشکلش کجاست؟
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
main()
{
char x[10][21],y[10],t[21];
int i,j,l=0,h=0,m,f=0;
clrscr();
cout<<"enter 10 name:";
for(i=0;i<10;i++)
gets(x[i]);
for(j=9;j>0;j--)
for(i=0;i<j;i++)
if(strcmp(x[i],x[i+1])>0)
{
strcpy(t,x[i]);
strcpy(x[i],x[i+1]);
strcpy(x[i+1],t);
}
cout<<"enter a name for search:";
gets(y);
while(l<=h && f==0)
{
m=(l+h)/2;
if(strcmp(y,x[m])==0)
f=1;
else if(strcmp(y,x[m])>0)
l=m+1;
else
h=m-1;
if(f==0)
cout<<"nist";
else
cout<<"hast";
}
getch();
}
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
main()
{
char x[10][21],y[10],t[21];
int i,j,l=0,h=0,m,f=0;
clrscr();
cout<<"enter 10 name:";
for(i=0;i<10;i++)
gets(x[i]);
for(j=9;j>0;j--)
for(i=0;i<j;i++)
if(strcmp(x[i],x[i+1])>0)
{
strcpy(t,x[i]);
strcpy(x[i],x[i+1]);
strcpy(x[i+1],t);
}
cout<<"enter a name for search:";
gets(y);
while(l<=h && f==0)
{
m=(l+h)/2;
if(strcmp(y,x[m])==0)
f=1;
else if(strcmp(y,x[m])>0)
l=m+1;
else
h=m-1;
if(f==0)
cout<<"nist";
else
cout<<"hast";
}
getch();
}