mấy cái đếm thời gian này thú thật e cũng ko rành lắm. hiện tại e đang học CTDL nên thầy bảo về tự tìm hiểu mà sao e chạy nó cứ 0.00 là sao mấy bác. có phải do em tự nhập phần tử n ít quá nên nó ko đếm dc ko có ai chỉ e vs.
#include "stdafx.h"
#include <iostream>
#include <time.h>
using namespace std;
#define MAX 100
//nhập mảng
void nhapmang(int a[], int n)
{
for (int i = 0; i < n; i++)
{
cout << "nhap phan tu thu a[" << i << "] :";
cin >> a[i];
}
}
//in mảng
void inmang(int a[], int n)
{
for (int i = 0; i < n; i++)
{
cout << a[i] << " ";
}
cout << endl;
}
// InterChange_Sort
void InterChange_Sort(int a[], int n)
{
int temp;
for (int i = 0; i < n-1; i++)
{
for (int j = i + 1; j < n; j++)
{
if (a[i]>a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int a[MAX], n,c,b;
cout << "nhap phan tu n=";
cin >> n;
nhapmang(a, n);
inmang(a, n);
cout << "mang sau khi sap xep la:";
clock_t start = clock();// ham bất đầu đếm thời gian thực hiện chương trình
InterChange_Sort(a, n);
inmang(a, n);
clock_t finish = clock();// ham đếm thời gian kết thúc
double duration = (double)(finish - start) / CLOCKS_PER_SEC;
cout <<"\n\n\n";
printf("Thoi gian thuc thi: %.2lf", duration);
system("pause");
return 0;
}

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?