Friday, July 31, 2009

Program in C using arrays to store a 10 integer data and find the second smallest and second largest element?

//assuming that your array is in array[10]





int max,min;


int smax,smin;


int c;


max=min=array[0];


smax=smin=max;


for(c=0;c%26lt;10;c++)


{


if(max%26lt;array[c]) max=array[c];


if(min%26gt;array[c]) min=array[c];


}


for(c=0;c%26lt;10;c++)


{


if(smax%26lt;array[c] %26amp;%26amp; array[c]%26lt;max) smax=array[c];


if(smin%26gt;array[c] %26amp;%26amp; array[c]%26gt;min) smin=array[c];


}

Program in C using arrays to store a 10 integer data and find the second smallest and second largest element?
The simplest way to do this, is to sort the array and then select the 2nd and 2nd last elements. How exactly you would do this, depends on what sorting algorithms you know, and as I'm guessing this is from a Computing I course, you will have probably just learned some. The pseudocode looks like this





void problem(int numbers[], int size) {


sort (numbers,size);


printf("%d,%d\n",numbers[1],numbers[size...


}


No comments:

Post a Comment