// array int, bubble sort, avg, max, min of 3 array<br>function : เรียงแบบ bubble sort อาเรย์ 3 ชุด หา max, min, avg
/* http://www.thaiall.com/tc */
#include <conio.h>
#include <stdio.h>
#include <iostream.h>
void getvalue(int n[3],char txt[10]);
void sortprocess(int n[3]);
void display(int n[3],char txt[10]);
int n[3], one[3], two[3], three[3], txt[10];
int i,j,maxinarray=0,max=0,tot=0,min=9999,num=3,tmp;
void main() {
clrscr();
getvalue(one,"One : ");
getvalue(two,"Two : ");
getvalue(three,"Three : ");
sortprocess(one);
sortprocess(two);
sortprocess(three);
display(one,"Sorting of one : ");
display(two,"Sorting of two : ");
display(three,"Sorting of three : ");
cout << "Max of all = "<< max << "\n";
cout << "Min of all = "<< min << "\n";
cout << "Average of all = "<< tot / 9;
getch();
}
void getvalue(int n[3],char txt[10]) {
for (i=0;i<num;i++) {
cout << txt << i+1 << " = ";
cin >> n[i];
if (max < n[i]) { max = n[i]; }
if (min > n[i]) { min = n[i]; }
tot = tot + n[i];
}
}
void sortprocess(int n[3]) {
for (i=0;i<num;i++) {
for (j=num-1;j>i;j--) {
if (n[j-1] > n[j]) {
tmp = n[j];
n[j] = n[j-1];
n[j-1] = tmp;
}
}
}
}
void display(int n[3],char txt[10]) {
maxinarray = 0;
cout << txt;
for (i=0;i<num;i++) {
cout << " " << n[i] ;
if (maxinarray < n[i]) { maxinarray = n[i]; }
}
cout << " Max : " << maxinarray << "\n";
}
| |