Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Array

aninganing Member Posts: 0

Enter the # of value of an array:
4

Enter the value of an array:
350
450
670
1000

The value in descending order:
1000
670
450
350

The 2nd largest element is:
670
The 2nd lowest element is:
450

The average of 2nd largest and 2nd lowest element is 560 is not in the array element.

can anyone help me? this is my final project on my subject compiler.. Im a newbie..

Comments

  • kasikasi Member Posts: 1

    #include <stdio.h>
    int main()
    {
    int a[10]; // u need to always specify the size of an array, dynamic size is not possible; if u know ur array size is always 4 then declare a[4];
    int i,j; // for loop indexing
    int n = 4; // since in ur case u said it is 4

    int temp<del></del>= 0;
    a[0] =350 ;
    a[1] = 450  ;
    a[2] = 670;
    a[3] = 1000;
    
    // for sorting
    for(j=0; j <4; j++)
    {   for(i = 0; i < 4-j: i++)
        {
            if(a[i] < a[i+1])
            {   
                temp= a[i];
                a[i] = a[i+1];
                a[i+1] = temp;
            }
        }
    }
    printf(second largest number %d\n", a[1]);
    printf(second smallest number %d\n", a[n-2]);
    
    int avg = (a[1] + a[n-2])/2;
    for(i= 0; i< 4;i++)
    {
        if(a[i] == avg)
        {
        printf("The average of 2nd largest and 2nd lowest element is 560 is in the array element %d", i+1);
            j = 1;
        }
    
    }
    if(j != 1)
    printf("The average of 2nd largest and 2nd lowest element is 560 is not in the array element.");
    return 0;
    

    }
    // this is the basic version of the code

  • OceanJeff40OceanJeff40 Member Posts: 9

    When you run it, does it work? If not, what is displayed?

Sign In or Register to comment.