Indian Railways - Seating Arrangement for Sleeper Class

QUESTION:


 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 1:
9

Sample Output 1:
Lower

Sample Input 2:
72

Sample Output 2:
Side Upper

SOLUTION:

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

Comments

Popular posts from this blog

Implementing a Fixed size Queue of maximum size 5 using an array

Implementing a Dynamically sized stack using array

Functions - Null Matrix