CNTT4A2 COMMUNITY

Thảo luận học tập


You are not connected. Please login or register

Chuyển đến trang : 1, 2  Next

Go downThông điệp [Trang 1 trong tổng số 2 trang]

7/3/2011, 9:44 pm
Ice.Tea
Ice.Tea

phương pháp Quickshort:


Code:
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
float a[100];
int n;
void QuickSort(float a[],int l,int r)
{
 int i,j;
 int x;
 i=l;
 j=r;
 x=a[(l+r)/2];
 do
  {
   while (a[i]<x)i++;
   while(a[j]>x)j--;
   if(j<=j)
    {
     if(i<j)
      {
       int temp=a[i];
       a[i]=a[j];
       a[j]=temp;
      }
   i++;
   j--;
     }
   }
   while(i<j);
   if(l<j)QuickSort(a,l,j);
   if(i<r)QuickSort(a,i,r);
}
void input(float a[],int n)
{
 int i;
 for (i = 1; i <= n; i++)
  {
   cout<<"a["<<i<<"]= ";
   cin>>a[i];
  }
}
void output(float a[],int n)
{
  int i;
  for (i = 1; i <= n; i++)
      cout<<a[i]<<"  ";
}
void main()
{
cout<<"Nhap n : ";cin>>n;
          if(n>0)
          {
          cout<<"Day ban dau: ";
          input(a,n);
          cout<<endl;
          cout<<"\nSap xep theo PP QuickSort:"<<endl;
          cout<<endl;
          QuickSort(a,1,n);
          output(a,n);
          }
getch();
 }
http://manhtuan-leo.blogspot.com/

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà Ice.Tea
7/3/2011, 10:52 pm
Ice.Tea
Ice.Tea

phương pháp Bubble sort:


Code:
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
float a[100];
int n;
void BubbleSort(float a[],int n)
{
 int temp;
 for(int i=1;i<n;i++)
 for(int j=n;j>i;j--)
 if(a[j]<a[j-1])
  {
   temp=a[j];
   a[j]=a[j-1];
   a[j-1]=temp;
  }
}
void input(float a[],int n)
{
 int i;
 for (i = 1; i <= n; i++)
  {
   cout<<"a["<<i<<"]= ";
   cin>>a[i];
  }
}
void output(float a[],int n)
{
  int i;
  for (i = 1; i <= n; i++)
      cout<<a[i]<<"  ";
}
void main()
{
cout<<"Nhap n : ";cin>>n;
          if(n>0)
          {
          cout<<"Day ban dau: ";
          input(a,n);
          cout<<endl;
          cout<<"\nSap xep theo PP Bubble sort:"<<endl;
          cout<<endl;
          BubbleSort(a,n);
          output(a,n);
          }
getch();
 }
http://manhtuan-leo.blogspot.com/

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà Ice.Tea
7/3/2011, 11:36 pm
Ice.Tea
Ice.Tea

phương pháp insertion sort:


Code:
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
float a[100];
int n;
void InsertionSort(float a[],int n)
{
float temp;
for(int i=2;i<=n;i++)
  {
   temp=a[i];
int vt=i;
while ((a[vt-1]>temp)&&(vt>1))
    {
  a[vt]=a[vt-1];
  vt=vt-1;
    }
a[vt]=temp;
  }
}
void input(float a[],int n)
{
int i;
for (i = 1; i <= n; i++)
  {
cout<<"a["<<i<<"]= ";
cin>>a[i];
  }
}
void output(float a[],int n)
{
  int i;
  for (i = 1; i <= n; i++)
cout<<a[i]<<"  ";
}
void main()
{
cout<<"Nhap n : ";cin>>n;
if(n>0)
{
cout<<"Day ban dau: ";
input(a,n);
cout<<endl;
cout<<"\nSap xep theo PP insertion sort:"<<endl;
cout<<endl;
InsertionSort(a,n);
output(a,n);
}
getch();
}
http://manhtuan-leo.blogspot.com/

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà Ice.Tea
8/3/2011, 12:12 am
Ice.Tea
Ice.Tea

phương pháp selection sort:

Code:
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
float a[100];
int n;
void SelectionSort(float a[], int n)
{
int min_pos;
    for (int i = 1; i < n; i++) {
        min_pos = i+1;
        for (int j = i + 2; j < n; j++)
            if (a[j] < a[min_pos])
                min_pos = j;
                if (a[min_pos]<a[i])
                {
        int temp = a[i];
        a[i] = a[min_pos];
        a[min_pos] = temp;
        }
    }
}
void input(float a[],int n)
{
int i;
for (i = 1; i <= n; i++)
  {
cout<<"a["<<i<<"]= ";
cin>>a[i];
  }
}
void output(float a[],int n)
{
  int i;
  for (i = 1; i <= n; i++)
cout<<a[i]<<"  ";
}
void main()
{
cout<<"Nhap n : ";cin>>n;
if(n>0)
{
cout<<"Day ban dau: ";
input(a,n);
cout<<endl;
cout<<"\nSap xep theo PP Selection Sort:"<<endl;
cout<<endl;
SelectionSort(a,n);
output(a,n);
}
}
http://manhtuan-leo.blogspot.com/

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà Ice.Tea
8/3/2011, 12:42 am
Ice.Tea
Ice.Tea

bai 1: ...max, min của mảng.....

Code:
#include <iostream.h>
#include <conio.h>
#include <math.h>
void main()
{
 float a[100],n;
 cout<<"nhap n = ";cin>>n;
 cout<<"nhap tu ban phim "<<n<<" so nguyen\n";
 for (int i=0;i<n;i++)
   cin>>a[i];
int max=a[0];
int min=a[0];
for ( i=1;i<n;i++)
   {
   if (a[i]>a[0])
      max=a[i];
   if (a[i]<a[0])
      min=a[i];
   }
 cout<<"so lon nhat : "<<max<<"\n";
 cout<<"so nho nhat : "<<min<<"\n";
 getch();
}
http://manhtuan-leo.blogspot.com/

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà Ice.Tea
8/3/2011, 12:49 am
Ice.Tea
Ice.Tea

bài 2: tính tổng 1+1/2+1/3+...+1/n

Code:
#include <iostream.h>
#include <conio.h>
#include <math.h>
void main()
{
 float i,n,sum;
 cout<<"nhap n = ";cin>>n;
sum=0;
for (i=1;i<=n;i++)
   sum+=1/i;
cout<<"tong 1+ 1/2 + 1/3 + ...+ 1/"<<n<<" = "<<sum<<"\n";
 getch();
}
http://manhtuan-leo.blogspot.com/

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà Ice.Tea
12/3/2011, 2:02 pm
Ice.Tea
Ice.Tea

ma trận :


Code:
#include <conio.h>
#include <iostream.h>
#include <math.h>
float b[100][100];
class MT
{
private:
int n;
public:
void nhap();
void xuat();

};
    void MT::nhap()
   {
   int i,j;
   cout<<"nhap cap cua ma tran";
   cin>>n;
   for(i=0;i<n;i++)
       {
      for(j=0;j<n;j++)
          {
         cout<<"b["<<i<<","<<j<<"]=";
         cin>>b[i][j];
         }
      }
   }
                   void MT::xuat()
               {
                  int i,j;
               for(i=0;i<n;i++)
                   {
                  for(j=0;j<n;j++)
                    {
                     cout<<b[i][j]<<"  ";

                  }
                  cout<<"\n";
                  }
               }

                   void main()
                  {
                  MT a;
                  a.nhap();
                  a.xuat();
                  getch();
                  }
http://manhtuan-leo.blogspot.com/

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà Ice.Tea
12/3/2011, 2:03 pm
Ice.Tea
Ice.Tea

tính tổng s= 1+x^2/2+x^3/4+...+x^n/n+1

Code:
#include <iostream.h>
#include <conio.h>
#include <math.h>

float x;
int n;
int tinh(float x, int n)
{

  if (n==1)
return 1;
  if (n>1)
return float((pow(x,n)/float(n+1)))+tinh(x,n-1);

}
void main()
{
cout<<"nhap x = ";cin>>x;
cout<<"nhap n = ";cin>>n;
cout<<"Tong = "<<tinh(x,n);
getch();
}
http://manhtuan-leo.blogspot.com/

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà Ice.Tea
12/3/2011, 2:04 pm
Ice.Tea
Ice.Tea

Số phức:

Code:
#include <iostream.h>
#include <conio.h>
#include <math.h>
class SP
{
 private:
   int i,r;
 public:
   void nhap();
   void tong();
   void in();
  SP()
  {
    r=0;
    i=0;
  }
};
SP a,b,c;
void SP::nhap()
{
cout<<"nhap r = ";cin>>r;
cout<<"nhap i = ";cin>>i;

}
void SP::tong()
{
c.r = a.r+b.r;
c.i = a.i+b.i;
}
void SP::in()
{
cout<<a.r<<"+j*"<<a.i<<" + "<<b.r<<"+j*"<<b.i<<" = " <<c.r<<"+j*"<<c.i<<"\n";
}
void main()
{

a.nhap();b.nhap();
a.tong();
c.in();
}
http://manhtuan-leo.blogspot.com/

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà Ice.Tea
12/3/2011, 2:06 pm
Ice.Tea
Ice.Tea

Phân số:



Code:
#include <iostream.h>
#include <conio.h>
#include <math.h>
int uc(int x, int y)
{
   while (x!=y)
   {
    if (x>y)
     x=x-y;
    else
     y=y-x;
     }
    return x;
   }
class PS
{
 private:
   int t,m;
 public:
   void tg();
   void nhap();
   void tong();
   void in();
};
PS a,b,s;
void PS::nhap()
{
cout<<"nhap tu = ";cin>>t;
cout<<"nhap  mau = ";cin>>m;

}
void PS::tong()
{

s.t = a.t*b.m+b.t*a.m;
s.m = a.m*b.m;

}
void PS::in()
{
cout<<s.t<<"/"<<s.m;
}
void PS::tg()
{
int u=uc(s.t,s.m);
s.t = s.t/u;
s.m = s.m/u;
}
void main()
{

a.nhap();b.nhap();
s.tong();
s.tg();
s.in();
}
http://manhtuan-leo.blogspot.com/

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà Ice.Tea
21/3/2011, 9:50 pm
thao_bg91
thao_bg91

nhung bai nay copy o dau hay lam vay.\
t doc ma chang hieu kai j ka?

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà thao_bg91
22/3/2011, 8:02 pm
Google bot
Google bot

google đoá e , sao mà ngu thế =))

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà Google bot
22/3/2011, 8:46 pm
Ice.Tea
Ice.Tea

anh em cứ Google đi ! đừng theo mấy code này nhé ! đây là bài của nhóm 4 !

còn không hiểu thì đọc giáo trình đi nhé !
http://manhtuan-leo.blogspot.com/

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà Ice.Tea
1/4/2011, 5:51 am
mansieunhan
mansieunhan

:6ghsd: nói :6ghsd: thật :6ghsd: mình :6ghsd: chán :6ghsd: học :6ghsd: tin :6ghsd: rổi :9567:

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà mansieunhan
5/4/2011, 7:10 pm
Ice.Tea
Ice.Tea

:458457:
http://manhtuan-leo.blogspot.com/

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà Ice.Tea
18/8/2011, 3:29 pm
vungoc
vungoc

Bài tìm max, min của mảng do Ice.TEA viết sai rồi.

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà vungoc
18/8/2011, 7:11 pm
kienhl
kienhl

Ice.Tea đã viết:phương pháp Quickshort:


Code:
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
float a[100];
int n;
void QuickSort(float a[],int l,int r)
{
 int i,j;
 int x;
 i=l;
 j=r;
 x=a[(l+r)/2];
 do
  {
   while (a[i]<x)i++;
   while(a[j]>x)j--;
   if(j<=j)
    {
     if(i<j)
      {
       int temp=a[i];
       a[i]=a[j];
       a[j]=temp;
      }
   i++;
   j--;
     }
   }
   while(i<j);
   if(l<j)QuickSort(a,l,j);
   if(i<r)QuickSort(a,i,r);
}
void input(float a[],int n)
{
 int i;
 for (i = 1; i <= n; i++)
  {
   cout<<"a["<<i<<"]= ";
   cin>>a[i];
  }
}
void output(float a[],int n)
{
  int i;
  for (i = 1; i <= n; i++)
      cout<<a[i]<<"  ";
}
void main()
{
cout<<"Nhap n : ";cin>>n;
          if(n>0)
          {
          cout<<"Day ban dau: ";
          input(a,n);
          cout<<endl;
          cout<<"\nSap xep theo PP QuickSort:"<<endl;
          cout<<endl;
          QuickSort(a,1,n);
          output(a,n);
          }
getch();
 }
\bạn tuấn lần sau giải thick phương pháp này để làm gì nhé, chứ viết ra,chẳng ai bít để làm gì cả, giải thick cho các bạn mới hiểu chứ :6845ert:
http://tin4a2uneti.tk

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà kienhl
18/8/2011, 8:34 pm
mansieunhan
mansieunhan

thang nay ve lam dep di

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà mansieunhan
19/8/2011, 1:23 pm
hà đức nghĩa
hà đức nghĩa

viết code ra chỉ để cho có việc để làm thôi viết xong chẳng biết mình viết cái gì nữa!!
http://lopc1.tk

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà hà đức nghĩa
19/8/2011, 4:40 pm
kienhl
kienhl

chuẩn :956785:
http://tin4a2uneti.tk

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà kienhl
21/8/2011, 3:25 pm
tinhbandep
tinhbandep

mình mà tự hiểu được thì học làm gì .cái gì cũng phải từ từ không nghe câu "mưa dầm thấm lâu ak ".mà không phải tự nhiên là hiểu được đâu

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà tinhbandep
21/8/2011, 3:29 pm
Ice.Tea
Ice.Tea

tinhbandep đã viết:mình mà tự hiểu được thì học làm gì .cái gì cũng phải từ từ không nghe câu "mưa dầm thấm lâu ak ".mà không phải tự nhiên là hiểu được đâu

Và H là ví dụ điển hình ! hiihihi ! :lfgghj:
http://manhtuan-leo.blogspot.com/

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà Ice.Tea
21/8/2011, 3:30 pm
tinhbandep
tinhbandep

hi :)
Tuấn quá khen , giờ Hảo cũng có biết gì mấy đâu , còn phải học hỏi nhiều he
:rtyshs:

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà tinhbandep
21/8/2011, 4:08 pm
Ice.Tea
Ice.Tea

vungoc đã viết:Bài tìm max, min của mảng do Ice.TEA viết sai rồi.

Run = Not error !

[You must be registered and logged in to see this image.]
http://manhtuan-leo.blogspot.com/

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà Ice.Tea
21/8/2011, 11:29 pm
kienhl
kienhl

vote :956785:
http://tin4a2uneti.tk

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà kienhl

Thích

Báo xấu [0]

Gửi một bình luận lên tường nhà Sponsored content

Về Đầu TrangThông điệp [Trang 1 trong tổng số 2 trang]

Chuyển đến trang : 1, 2  Next

« Xem bài trước | Xem bài kế tiếp »

Bài viết mới cùng chuyên mục

    Bài viết liên quan với Code tham khảo BT Tin

      Quyền hạn của bạn:

      Bạn không có quyền trả lời bài viết