
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Find Length of Bridge Using Speed and Length of Train in C++
In this problem, we are given the length (L) and speed (S) of the train along with the time taken by it to pass the bridge. Our task is to create a program to find Length of Bridge using Speed and Length of Train in C++.
Problem Description
We need to find the length of the bride using the speed of the train, the time taken by it to cross the bridge, And the length of the train.
Let’s take an example to understand the problem,
Input: L = 310, S = 45m/sec , time = 12 sec
Output: 230 m
Solution Approach
The whole train passes through the bridge at a speed of S in T. The time taken is for the train entering the bridge to the train leaving the bridge. So, the distance will be the length of train (L) + length of bridge(B).
Formulating it,
S*T = (L+B)
Finding the length of the bridge (B),
B = S*T - L
Example
#include <iostream> using namespace std; int findBridgeLenght(int L, int S, int T) { int B = ( (S*T) - L); return B; } int main() { int L = 150, S = 45, T = 25; cout<<"The length of the bridge is "<<findBridgeLenght(L, S, T); return 0; }
Output
The length of the bridge is 975