To manage the availability of the rooms in his hotel, the owner asks you to write a program that uses an array rooms[10][40] whose values are 0s and 1s. The value of rooms[i][j] is 1 if the room j of the floor i is occupied, this value is 0 if this room is free. Write a program that asks the user to enter the values of the array rooms[10][40], checking that the entered values are exclusively 0s and 1s. The program then prompts the user to enter a floor number and a room number and displays the status (free or occupied) of this room on this floor.


Difficulty level
This exercise is mostly suitable for students
#include <stdio.h>
#include <math.h>
int main()
{
    int rooms[10][40];
    int I, J;
    int f, r;
    

    for (I=0 ; I<10 ; I++)
        for (J=0 ; J<40 ; J++)
        {
            do{
                printf("Enter Rooms[%d][%d] : ", I, J);
                scanf("%d", &rooms[I][J]);
            }while(rooms[I][J]!=0 || rooms[I][J]!=1 );
        }
 
    do{
        printf("Enter floor number: ");
        scanf("%d", &f);
    }while(f<=0 || f>10);
    
    do{
        printf("Enter room number: ");
        scanf("%d", &r);
    }while(r<=0 || r>40);
    
    if(rooms[f][r]==1)
        printf("Room is occupied\n");
    else
        printf("Room is free\n");
    
    return 0;
} 
 

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Search into a table based on hash coalesced with separated zones