- 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

# C Program for Number of stopping station problem

**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.

## Problem Explanation

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)!

#### Algorithm

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.

#### Example

#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"); }

#### Output

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
- Python Program for Activity Selection Problem
- Python Program for Subset Sum Problem
- Gas Station in C++
- Minimum Number of Platforms Problem
- Minimum Number of Jumps 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?
- C++ Program to Implement Network_Flow Problem
- Bin Packing Problem (Minimize number of used Bins) in C++?