Randomly generates an array of 10 elements and finds the extremum.
1 #define_crt_secure_no_warnings2 3#include <stdio.h>4#include <stdlib.h>5#include <time.h>6 7 8 Main ()9 {Ten time_t ts; One ASrand ((unsignedint) Time (&ts)); - - inta[Ten]; the inti; - intMax//to save the maximum value - intMaxi//Subscript to hold the maximum value - intmin; + intMini; - + for(i =0; I <Ten; i++) A { atA[i] = rand ()% -; -printf"%d,%x\n", A[i], &a[i]); - } - -max = a[0];//Suppose the first one is the largest number -Maxi =0;// inMin = a[0];//Suppose the first one is the smallest number -Mini =0;// to + for(i =1; I <Ten; i++)//Select comparison - { the if(A[i] >max) * { $Max =A[i];Panax NotoginsengMaxi =i; - } the } + A for(i =1; I <Ten; i++)//Select comparison the { + if(A[i] <min) - { $Min =A[i]; $Mini =i; - } - } the -printf"The maximum value is%d and the subscript is%d\n", Max, maxi);Wuyiprintf"The minimum value is%d and the subscript is%d\n", Min, mini); the -System"Pause"); Wu}
Array _ Select Sort