4 Replies - 33866 Views - Last Post: 18 December 2008 - 02:51 PM Rate Topic: -----

#1 sw33tCandy  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 17-December 08

Find the largest & smallest number in integer array -c code

Posted 18 December 2008 - 01:18 PM

:blink:
How to find the largest & smallest number in integer array -c code
???????????????????????????????????? :blink:
Is This A Good Question/Topic? 1

Replies To: Find the largest & smallest number in integer array -c code

#2 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5247
  • View blog
  • Posts: 27,070
  • Joined: 10-May 07

Re: Find the largest & smallest number in integer array -c code

Posted 18 December 2008 - 01:23 PM

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.
Was This Post Helpful? 0
  • +
  • -

#3 amir_ju  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 82
  • Joined: 20-June 08

Re: Find the largest & smallest number in integer array -c code

Posted 18 December 2008 - 01:43 PM

On the assumption that you've stored array length in 'len', and the integer array is 'A' this is the code:
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



----------------------------------------------
If this was helpful click the link below :v:
Was This Post Helpful? 1

#4 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,141
  • Joined: 14-September 07

Re: Find the largest & smallest number in integer array -c code

Posted 18 December 2008 - 02:34 PM

Alternately you could sort the array.
Was This Post Helpful? 0
  • +
  • -

#5 stratack  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 16-December 08

Re: Find the largest & smallest number in integer array -c code

Posted 18 December 2008 - 02:51 PM

This how you calculate the max which means largest number in otherwise u calculate min the smallest number !!!
I hope this will help u anyway....



 


#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;
}






Was This Post Helpful? 0
  • +
  • -

Page 1 of 1