Velocidad del bote en aguas tranquilas a partir de la velocidad de la corriente y los tiempos tomados

Escriba un programa para determinar la velocidad del bote en aguas tranquilas (B) dada la velocidad de la corriente (S en km/h), el tiempo que tarda (para el mismo punto) el bote río arriba (T1 en h) y río abajo (T2 en h).

Ejemplos: 

Input : T1 = 4, T2 = 2, S = 5
Output : B = 15

Input : T1 = 6, T2 = 1, S = 7
Output : B = 9.8  

Requisito previo: Velocidad de la embarcación aguas arriba y aguas abajo La
velocidad de la embarcación en aguas tranquilas se puede calcular utilizando la siguiente fórmula. 
B = S*((T1 + T2) / (T1 – T2))

¿Cómo funciona esta fórmula?  
Dado que el punto es el mismo, la distancia recorrida aguas arriba debe ser la misma que aguas abajo. 
Por lo tanto, 
(B – S) * T1 = (B + S) * T2 
B(T1 – T2) = S*(T1 + T2) 
B = S*(T1 + T2)/(T1 – T2)

C++

// CPP program to find speed of boat in still water
// from speed of stream and times taken in downstream
// and upstream
#include <iostream>
using namespace std;
 
// Function to calculate the speed of boat in still water
float still_water_speed(float S, float T1, float T2)
{
    return (S * (T1 + T2) / (T1 - T2));
}
 
int main()
{
    float S = 7, T1 = 6, T2 = 1;
    cout << "The speed of boat in still water = "<<
             still_water_speed(S, T1, T2)<<" km/ hr ";
    return 0;
}

Java

// Java program to find speed of boat in still water
// from speed of stream and times taken in downstream
// and upstream
import java.io.*;
 
class GFG
{
    // Function to calculate the
    // speed of boat in still water
    static float still_water_speed(float S, float T1, float T2)
    {
        return (S * (T1 + T2) / (T1 - T2));
    }
 
    // Driver code
    public static void main (String[] args) {
        float S = 7, T1 = 6, T2 = 1;
        System.out.println("The speed of boat in still water = "+
                            still_water_speed(S, T1, T2)+" km/ hr ");
     
    }
}
 
// This code is contributed by vt_m.

Python3

# Python3 program to find speed of boat
# in still water from speed of stream and
# times taken in downstream and upstream
 
# Function to calculate the
# speed of boat in still water
def still_water_speed(S, T1, T2):
    return (S * (T1 + T2) / (T1 - T2))
     
# Driver code
S = 7; T1 = 6; T2 = 1
print("The speed of boat in still water = ",
       still_water_speed(S, T1, T2), " km/ hr ")
        
# This code is contributed by Anant Agarwal.

C#

// C# program to find speed of boat
// in still water from speed of stream
// and times taken in downstream
// and upstream
using System;
 
class GFG {
     
    // Function to calculate the
    // speed of boat in still water
    static float still_water_speed(float S, float T1,
                                            float T2)
    {
        return (S * (T1 + T2) / (T1 - T2));
    }
 
    // Driver code
    public static void Main()
    {
        float S = 7, T1 = 6, T2 = 1;
        Console.WriteLine("The speed of boat in still water = " +
                      still_water_speed(S, T1, T2) + " km/ hr ");
    }
}
 
// This code is contributed by vt_m.

PHP

<?PHP
// PHP program to find speed of
// boat in still water from speed
// of stream and times taken in
// downstream and upstream
 
// Function to calculate the speed
// of boat in still water
function still_water_speed($S, $T1, $T2)
{
    return ($S * ($T1 + $T2) /
                 ($T1 - $T2));
}
 
// Driver Code
$S = 7;
$T1 = 6;
$T2 = 1;
echo("The speed of boat in still water = " .
           still_water_speed($S, $T1, $T2) .
                                " km/hr ");
 
// This code is contributed by Smitha
?>

Javascript

<script>
 
// Javascript program to find speed of
// boat in still water from speed
// of stream and times taken in
// downstream and upstream
   
// Function to calculate the speed
// of boat in still water
function  still_water_speed(S, T1, T2)
{
    return (S * (T1 + T2) / (T1 - T2));
}
   
// Driver Code
var S = 7;
var T1 = 6;
var T2 = 1;
document.write("The speed of boat in still water = " +
               still_water_speed(S, T1, T2) + " km/hr ");
                
// This code is contributed by bunnyram19
 
</script>

Producción: 

The speed of boat in still water = 9.8 km/hr

Complejidad de tiempo: O(1)

Espacio Auxiliar: O(1)
 

Publicación traducida automáticamente

Artículo escrito por mohitw16 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *