Answer to Question #291862 in C for sunny

Question #291862

The placement session has begun in a college. There is N number of students standing outside an interview room in a line. It is given that the person who goes first has higher chances of selection.


Each student has a number associated with them representing their problem-solving capability. The higher the capability the higher the chances of selection. Now every student wants to know the number of students ahead of him with higher problem-solving capability.


using structure in code


Input: 6(number of students) {4 , 9 , 5 , 3 , 2 , 10}


Output: {0 , 0 , 1 , 3 , 4 , 0}


1
Expert's answer
2022-01-29T06:24:33-0500
#include <stdio.h>
#define N 6


void number_ahead(int n, int students[], int ahead[])
{
    int i, j;


    for (i=0; i<n; i++) {
        ahead[i] = 0;
        for (j=i-1; j>=0; j--) {
            if (students[j] > students[i]) {
                ahead[i]++;
            }
        }
    }
     
}

int main() {
    int i;
    int students[N] = {4, 9, 5, 3, 2, 10};
    int ahead[N];

    number_ahead(N, students, ahead);

    for (i=0; i<N; i++) {
        printf("%d ", ahead[i]);
    }

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS