Lab Allocation III

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. How many of the 3 labs can accommodate 'n' students?

Input and Output Format:
Refer sample input and output.

All text in bold corresponds to input and the rest corresponds to output.
Sample Input and Output 1:
Enter x
30
Enter y
40
Enter z
20
Enter n
25
2 lab(s) can accommodate 25 students

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

  • #include
  • int main()
  • {
  • int x,y,z,n,c=0;
  • printf("Enter x");
  • scanf("%d",&x);
  • printf("\nEnter y");
  • scanf("%d",&y);
  • printf("\nEnter z");
  • scanf("%d",&z);
  • printf("\nEnter n");
  • scanf("%d",&n);
  • if(c==0)
  • if(n<=x)
  • c++;
  • if(n<=y)
  • c++;
  • if(n<=z)
  • c++;
  • printf("\n%d lab(s) can accommodate %d students",c,n);
  • if(c>0)
  • printf("\nNone of the labs can accommodate 50 students");
  • return 0;
  • }

No comments: