?? dxyy3.cpp
字號:
// dxyy3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream.h"
int main()
{
int i,j,t,n=0,num;
int a[10];
//從鍵盤為數(shù)組元素賦值
for(i=0;i<10;i++)
{
cout<<"a["<<i<<"]=";
cin >>a[i];
}
//對數(shù)組排序
for(i=0;i<9;i++)
{
for(j=0;j<9-i;j++)
{
if(a[j] > a[j+1])
{
t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
}
}
cout<<"輸入要查找的數(shù)據(jù):"<<"\n";
cin >>num;
cout<<"輸出數(shù)組:"<<"\n";
for(i=0;i<10;i++)
{
cout<<a[i]<<"\t";
if((i+1)%3 == 0)
{
cout<<"\n";
}
}
cout<<"\n";
int left = 0,right = 9,mid;
while(left <= right)
{
mid = (left+right)/2;
if(a[mid] == num)
{
cout<<"要查找的元素是:"<<"\n";
cout<<"a["<<mid<<"]="<<num<<"\n";
n++;
}
if(a[mid] < num)
{
left = mid+1;
}
else
{
right = mid-1;
}
}
if(n == 0)
{
cout<<"要查找的元素不存在!"<<"\n";
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -