Indian Railway – Seating arrangement for Sleeper Class

Write a program to determine the type of berth when the seat/berth number in the train is given.
Input Format:

Input consists of a single integer. Assume that the range of input is between 1 and 72.

Output Format:

Output consists of a single string. [Upper or Middle or Lower or Side Lower or Side Upper]

Sample Input 2:

72

Sample Output 2:

Side Upper

 

code:

#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    if(n<=72&&n>=1)
    {
        if(n%8==0)
        {
            printf("Side Upper");
        }
        else if(n%8==7)
        {
            printf("Side Lower");
        }
        else if(n%8==4||n%8==1)
        {
            printf("Lower");
        }
        else if(n%8==5||n%8==2)
        {
            printf("Middle");
        }
        else
        {
            printf("Upper");
        }
        
    }
    
  
    return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *