Answer to Question #282270 in C for Shan

Question #282270

Question 1



Revisit Later



Compil



How to Attempt?



Placement Season Begins



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



Each student has a number associated with them known as the problem solving capability (PSC). The higher the capability, the higher the chances of selection. Now, each student wants to know the number of students ahead of him/her who have more problem-solving capability than him/her.



Find this number for each student.



Input Specification:



input1: An integer N. which denotes the number of students present. input2: An array of size N, denoting the problem-solving capability of the students



1
Expert's answer
2021-12-23T11:10:08-0500
#include <stdio.h>
#define SIZE 100

int main() {
    int n, i, j;
    int PSC[SIZE];
    int ahead[SIZE];

    scanf("%d", &n);
    for (i=0; i<n; i++) {
        scanf("%d", &PSC[i]);
        ahead[i] = 0;
    }

    for (i=0; i<n; i++) {
        for (j=0; j<n; j++) {
            if (PSC[i] < PSC[j]) {
                ahead[i]++;
            }
        }
    }

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

    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