Recent Posts

Code C++: Tìm kiếm nhị phân không sử dụng đệ quy

-

#include<stdio.h>
#include<iostream>
using namespace std;
int a[100],n,x;
int TimKiemNhiPhan(int M[], int N, int X){
int First = 0;
int Last = N - 1;
while (First <= Last){
int Mid = (First + Last)/2;
if (X == M[Mid])
return Mid;
if (X < M[Mid])
Last = Mid - 1;
else
First = Mid + 1;
}
return -1;
}
void nhap(){
cout<<"Nhap so phan tu mang: "; cin>>n;
for(int i=0;i<n;i++){
cout<<"a["<<i<<"]= "; cin>>a[i];
}
cout<<"Nhap so can tim: "; cin>>x;
}
int main(){
nhap();
cout<<"So lan xuat hien: "<<TimKiemNhiPhan(a,n,x);
return 0;
}

Related Post:

  • Code C#: About Dialog<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  Title="About WPF" SizeToContent="WidthAndHeight" Background="Red">  <StackPanel>  <Label FontWeight="Bold" FontSize="20" Foreground="blue">    WPF Version   </Label>  <Label>2012</Label>  <Label>Installe… Read More
  • Code C#: Code Examples sample source codesCenter form window  using System;  using System.Drawing;  using System.Collections;  using System.ComponentModel;  using System.Windows.Forms;  using System.Data;  public class Form1 : System.Windows.Forms.Form {    private Button myButton;     public Form1()   {      this.AutoSc… Read More
  • Code C#: Tổng 2 số nguyên a, b nhập từ bàn phím (Console)using System;namespace Tong2so{    class Program {        static void Main(string[] args) {            int a, b, kq;            Console.WriteLine(" Nhập gia tri a: ");            a = int.Parse(Console.ReadLine());       … Read More
  • Code C#: Code Examples sample source codesGet selected checkbox list itemsusing System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;public class Form1 : System.Windows.Forms.Form {   private System.Windows.Forms.CheckedListBox chkListPossibleValues;   private System.Windows.Forms.ListBox lstSelected;   priv… Read More
  • Code C#: Giải phương trình bậc nhất (Console)using System; namespace PhuongTrinhBacNhat{    class Program {        static void Main(string[] args) {            Console.Write("Nhap he so a :");            int a = int.Parse(Console.ReadLine());            Console.Write("Nhap h… Read More
  • Code C#: Nhập, xuất với mảng 1 chiều (Console)using System;static void Main(string[] args){    int[] a = new int[10];    //nhap gia tri cho mang 1 chieu    for (int i = 0; i < 10; i++){        Console.Write("Nhap a[{0}]=", i);        a[i] = int.Parse(Console.ReadLine());    }    //xuat mang 1 chieu    for (int i… Read More




Klik untuk melihat kode: :) =( :s :D :-D ^:D ^o^ 7:( :Q :p T_T @@, :-a :W *fck* x@