HackerRank: Drawing Book Solution in C

A teacher asks the class to open their books to a page number. A student can either start turning pages from the front of the book or from the back of the book. They always turn pages one at a time. When they open the book, page 1 is always on the right side:

int pageCount(int n, int p) {
int value=0;
 if(p<=n/2) value=p/2;
 else value = n/2 -  p/2;
 return value;
}

Leave a Comment