Question:
take 10 number from array and find which one is highest and lowest?
Yaman
2011-08-29 09:29:40 UTC
array
Four answers:
kennywalter.com
2011-08-29 09:41:28 UTC
Pseudocode:

min, max = array[0]



for(int i=1; i<10; i++)

{

if(array[i]
min = array[i];

else if(array[i]>max)

max = array[i];

}
?
2011-08-29 11:39:44 UTC
This can be done easily in PowerBASIC. (Or any language, for that matter. It's a simple problem.)



In PowerBASIC, simply use the sort array statement to first sort the array.



Once done, element #1 in the array is the largest, and element #10 in the array is the smallest. (Or vice versa, depending upon if you sort in ascending or descending order.)



If you don't have such a statement in your language, simply loop through the entire array one time. Have two different holding areas. One holding area will hold the current largest element found, the other the smallest current element found. Compare each number in the array to each element, and move it there if desired.
?
2011-08-29 10:25:14 UTC
but in which programming language C,C#,C++,java,javaScript,VB,VBScript????

Well anyways here is the trick

1.Take all numbers in an array ,array name is "array1".Take the length of array(total number of variables in an array) as 10

2.take 2 integer variable "Bignum=0" and "Smallnum=array1[1]"

3 now make a for loop form 0 to 9 like i dont know which lang u r studing but in most languages it is like (int i=0;i<10;i++)

3.inside the loop you have to write 2 if statements..

first>>>>> if ( Bignum < array1[i]) then Bignum=array1[i]

second>>>>>>if(Smallnum >array1[i]) then Smallnum==array1[i]

now in the end display the values in Bignum and Smallnum

thats it ...i mean its just for beginners



here is the program in C# language

int[] array1={14,4,2,6,7,3,6,5,23,12};

int Bignum=0,Smallnum=array1[1];

for(int i =0;i<10;i++)

{

if(Bignum
{

Bignum=array1[i];

}

if(Smallnum >array1[i])

{

Smallnum=array1[i]

}

}

Console.WriteLine("The largest number is"+Bignum);

Console.WriteLine("The Smallest number is "+Smallnum);
?
2011-08-29 09:37:46 UTC
What language?


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...