How to find the largest & smallest number in integer array -c code
????????????????????????????????????




Posted 18 December 2008 - 01:18 PM
Posted 18 December 2008 - 01:23 PM
Posted 18 December 2008 - 01:43 PM
int max_index = 0,
min_index = 0;
for(int i=0; i<len; i++) {
if(A[min_index] > A[i])
min_index = i;
else if(A[max_index] < A[i])
max_index = i;
}
// now the A[max_index] is the largest
// and A[min_index] is the smallest element
Posted 18 December 2008 - 02:51 PM
#include<iostream>
using namespace std;
main(){
int number,max;
cout<<"Give a number";
cin>>number;
max=number;
while(cin.get()!=EOF){
cout<<"Give a number";
cin>>number;
if(number>max)
max=number;
}
cout<<"Max"<<max;
}
|
|
Query failed: connection to localhost:3312 failed (errno=111, msg=Connection refused).
|
