For better understanding refer YouTube Tutorial Video
CODE:
/***SOLUTION BY CODING DEMONS***/
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, p, f, b; //Variables
cin >> n; //total pages
cin >> p; //required page number
f = p/2;
//calculate the pages from front
//To calculate the pages from back
//check total pages are even or not
if(n%2 == 0) //for Even
b = (n-p+1)/2;
//formula for Even
else //for Odd
b = (n-p)/2;
//formula for Odd
cout << min(f, b);
//Print the minimum
// from front or back
}
/********END********/
!! SUBSCRIBE FOR MORE CODES & VIDEOS !!
0 Comments