在c语言中怎么输入一组数字存储在数组里
答案:1 悬赏:0 手机版
解决时间 2021-11-18 22:59
- 提问者网友:蓝莓格格巫
- 2021-11-17 22:28
在c语言中怎么输入一组数字存储在数组里
最佳答案
- 五星知识达人网友:持酒劝斜阳
- 2021-11-17 23:06
#define N 100
int main()
{
int iarray[100];
int num;
for(int i = 0; i < N; i++)
{
iarray[i] = i*2;
}
printf("请输入一个数字:");
scanf("%d", &num);
int first = 0;
int last = N-1;
int half = 0;
bool bfind = false;
time_t start, end;
start = time(NULL);
do
{
half = (first+last)/2;;
if( num == iarray[half])
{
bfind = true;
break;
}
else if( num > iarray[half])
{
first = half + 1;
}
else
{
last = half - 1;
}
} while( first <= last );
end = time(NULL);
if(bfind)
{
printf("num = %d,pos = %d\n",num, half);
}
else
{
printf("not found!\n");
}
printf("endtime = %d, starttime = %d\n", end, start);
printf("使用的时间为:%.16f\n", (double)(end - start)/CLOCKS_PER_SEC);
system("pause");
return 1;
}
int main()
{
int iarray[100];
int num;
for(int i = 0; i < N; i++)
{
iarray[i] = i*2;
}
printf("请输入一个数字:");
scanf("%d", &num);
int first = 0;
int last = N-1;
int half = 0;
bool bfind = false;
time_t start, end;
start = time(NULL);
do
{
half = (first+last)/2;;
if( num == iarray[half])
{
bfind = true;
break;
}
else if( num > iarray[half])
{
first = half + 1;
}
else
{
last = half - 1;
}
} while( first <= last );
end = time(NULL);
if(bfind)
{
printf("num = %d,pos = %d\n",num, half);
}
else
{
printf("not found!\n");
}
printf("endtime = %d, starttime = %d\n", end, start);
printf("使用的时间为:%.16f\n", (double)(end - start)/CLOCKS_PER_SEC);
system("pause");
return 1;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯