There are 3 labs in the CSE department(L1, L2, and L3) with a seating capacity of x, y, and z. A single lab needs to be allocated to a class of 'n' students. The labs need to be utilized to the maximum i.e the number of systems that are not being used should be minimal. Which lab needs to be allocated to this class?

Input and Output Format:
Assume that x, y, and z are always distinct.
Refer sample input and output.

All text in bold corresponds to the input and the rest corresponds to output.
Sample Input and Output:
Enter x
30
Enter y
40
Enter z
20
Enter n
25
L1 should be allocated to this class


Sample Input and Output 2:
Enter x
30
Enter y
40
Enter z
20
Enter n
50
None of the labs can be allocated


Program Code:
#include<stdio.h>
int main()
{
    int x, y, z, n, a, b, c;
    printf("Enter x\n");
    scanf("%d", &x);
    printf("Enter y\n");
    scanf("%d", &y);
    printf("Enter z\n");
    scanf("%d", &z);
    printf("Enter n\n");
    scanf("%d", &n);
    a=x-n;
    b=y-n;
    c=z-n;
    if(a<0&&b<0&&c<0)
    printf("None of the labs can be allocated");
    else if(a<b&&a<c)
    printf("L1 should be allocated to this class"); 
    else if(b<a&&b<c)
    printf("L2 should be allocated to this class"); 
     else
    printf("L3 should be allocated to this class"); 
    return 0;
}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: