1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <math.h>
int _tmain(int argc, _TCHAR* argv[]) {
int n = 1;
std::cin >> n;
std::cout << "Remplissage du tableau avec n=" << n << " valeurs..." << std::endl;
int table[] = {0};
fill(table,n);
sort(table,n);
getch();
}
void fill(int *t,int s) {
for(int i=0;i<s;i=i+1) {
t[i] = rand();
std::cout << "valeur a n=" << i <<" est " << t[i] << std::endl;
}
}
void sort(int *t, int s) {
int max = get_max(t,s);
std::cout << "le maximum est: " << t[max] <<" a n=" << max << std::endl;
}
int get_max(int *t, int s) {
int w[] = {t[0],0};
for(int i = 0;i<s;i=i+1) {
if(t[i] > w[0]) { w[0] = t[i]; w[1] = i; }
}
return w[1];
} |
Partager