- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

**Problem statement **− A program to find the number of ways in which a train will stop in **r** stations out of **n** stations so that no two stopping stations are consecutive.

This program will calculate the number of ways i.e. permutations in which the train will stop. Here, the train will travel from point **X** to **Y**. Between these points, there are **n **stations. The train will stop on** r** stations of these **n** stations given the conditions that while stopping on** r **stations the train should not stop in two consecutive stations.

This permutation can be found using the direct ^{n}p_{r} formula.

Let's take a few examples,

Input : n = 16 , r = 6 Output : 462

**Explanation** − The number of ways the train can stop at 6 stops out of 16 stops fulfilling the condition is found using the permutation formula given by

^{n}p_{r} or p(n, r) = n! ∕ (n-r)!

Input : total numbers of stations n and number of stations train can stop r. Step 1 : For values of n and r calculate the value of p(n,r) = n! / (n-r)! Step 2 : print the value of p(n,r) using std print method.

#include<stdio.h> int main(){ int n = 16, s = 6; printf("Total number of stations = %d\nNumber of stopping station = %d\n", s, n); int p = s; int num = 1, dem = 1; while (p!=1) { dem*=p; p--; } int t = n-s+1; while (t!=(n-2*s+1)) { num *= t; t--; } if ((n-s+1) >= s) printf("Possible ways = %d", num / dem); else printf("no possible ways"); }

Total number of stations = 16 Number of stopping station = 6 Possible ways = 462

- Related Questions & Answers
- Python Program for Number of stopping station problem
- Minimum Number of Platforms Required for a Railway Station using C++.
- Find the Number of Stopping Stations using C++
- C Program for Activity Selection Problem
- Gas Station in C++
- Python Program for Activity Selection Problem
- Python Program for Subset Sum Problem
- Minimum Number of Jumps Problem
- Minimum Number of Platforms Problem
- C++ Program to Solve Travelling Salesman Problem for Unweighted Graph
- Python Program for 0-1 Knapsack Problem
- Program for factorial of a number in C program
- C/C++ Program for Finding the Number Occurring Odd Number of Times?
- Bin Packing Problem (Minimize number of used Bins) in C++?
- C++ Program to Implement Network_Flow Problem

Advertisements