c question, what is the problem ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

c question, what is the problem ?

#include <stdio.h> #include <conio.h> #include <stdlib.h> int blsearch(int st[],int len,int no) { int mid,low=0,high=len-1; while(low<=high) { mid=(low+high)/2; if(no<st[mid]) high=mid-1; else if(no>st[mid]) low=mid+1; else return mid; } return -1; } void binarysearch(int temp[],int len,int y) { int i,j,item,a; for(i=len-1;i>0;i--) for(j=0;j<i;j++) if(temp[j]>temp[j+1]) { item=temp[j]; temp[j]=temp[j+1]; temp[j+1]=item; } a =blsearch(temp,len,y); if(a==-1) printf("\n number %d not exsit in list",y); else printf("\n number %d exsit in list:",y); } int lsearch(int st[],int len,int y) { int i; for(i=0;i<len;i++) if(st[i]==y) return i; return -1; } void linearsearch(int temp[],int len,int y) { if(lsearch(temp,len,y)==-1) printf("\n number %d not exsit in list",y); else printf("\n number %d exsit in list:",y); } int main() { int i,len,n,x ,y; printf("enter a len:\n"); scanf("%d",len); int a[len]; printf("enter a members:\n"); for(i=0;i<len;i++) scanf("%d",&n); sytem("cls"); printf("if you are binary search enter a 1\n if you are linear search enter a 2\n"); scanf("%d",&x); system("cls"); printf("what number do you want to look for?\n"); scanf("%d",&y); if(x==1) binarysearch(a,len,y); else linearsearch(a,len,y); return 0; }

16th Dec 2018, 12:33 PM
Fatemeh Rahimzadeh
Fatemeh Rahimzadeh - avatar
2 Answers
0
مرسی خیلی ممنون
16th Dec 2018, 4:57 PM
Fatemeh Rahimzadeh
Fatemeh Rahimzadeh - avatar
0
یه سوال اگه بخوام خونه ی اون عددی که دنبالش می گردیم رو چاپ کنه باید چی کار کنیم ؟
16th Dec 2018, 5:48 PM
Fatemeh Rahimzadeh
Fatemeh Rahimzadeh - avatar