Encuentre la velocidad de la corriente a partir de la velocidad del hombre dada en aguas arriba y aguas abajo

Un bote tarda N1 h en remar X1 km río abajo de un río y tarda N2 h en recorrer una distancia de X2 km río arriba. Encuentre la velocidad de la corriente.

Input: 3 15 2 5
Output: 17.5 km/hr

Input: 4 29 7 30
Output: 47 km/hr

Acercarse:

  • Tome la entrada de los usuarios
  • Calcular la tasa de aguas abajo y aguas arriba. La tasa se puede calcular usando la fórmula.

Speed = \frac{distance}{time}

  • Luego, calcula la velocidad de la corriente. Está dada por la fórmula –

Rate of Stream = \frac{1}{2}(downstream - upstream)

A continuación se muestra la implementación. 

C++

#include<iostream>
using namespace std;
 
void rate(float down, float up)
{
     
    // Stream rate
    float rate = 0.5 * (down - up);
    cout << rate <<  " Km/hr";
}
 
// Driver Code
int main()
{
   
    // Distance and time downstream
    float N1 = 3;
    float X1 = 15;
 
    // Distance and time upstream
    float N2 = 2;
    float X2 = 5;
 
    // Rate of downstream and upstream
    float Rate_downstream = X1 / N1;
    float Rate_upstream = X2 / N2;
 
    rate(Rate_downstream, Rate_upstream);
    
   return 0;
}
 
// This code is contributed by Surbhi Tyagi.
                    

Java

/*package whatever //do not write package name here */
 
import java.io.*;
 
public class GFG
{
     
public static void rate(float down, float up)
{
     
    // Stream rate
    double rate = 0.5 * (down - up);
    System.out.println(rate+ " Km/hr");
}
  
// Driver Code
public static void main(String args[])
{
   
// Distance and time downstream
float N1 = 3;
float X1 = 15;
 
// Distance and time upstream
float N2 = 2;
float X2 = 5;
 
// Rate of downstream and upstream
float Rate_downstream = X1 / N1;
float Rate_upstream = X2 / N2;
 
rate(Rate_downstream, Rate_upstream);
    }
}
 
// This code is contributed by sravankumar8128.

Python3

def rate(down, up):
 
    # stream rate
    rate = 0.5*(down - up)
    print(rate, " Km/hr")
 
 
# Driver Code
# Distance and time downstream
N1 = 3
X1 = 15
 
# Distance and time upstream
N2 = 2
X2 = 5
 
# Rate of downstream and upstream
Rate_downstream = X1/N1
Rate_upstream = X2/N2
 
rate(Rate_downstream, Rate_upstream)

Javascript

<script>
 
function rate(down, up)
{
     
    // Stream rate
    var rate = 0.5 * (down - up);
    document.write(rate, " Km/hr");
}
  
// Driver Code
 
// Distance and time downstream
var N1 = 3;
var X1 = 15;
 
// Distance and time upstream
var N2 = 2;
var X2 = 5;
 
// Rate of downstream and upstream
var Rate_downstream = X1 / N1;
var Rate_upstream = X2 / N2;
 
rate(Rate_downstream, Rate_upstream);
 
// This code is contributed by Ankita saini
                     
</script>

C#

// C# program for the above approach
using System;
class GFG {
 
    static double rate(float down, float up)
    {
 
        // Stream rate
        double rate = 0.5 * (down - up);
        return rate;
    }
 
    // Driver Code
    public static void Main()
    {
        // Distance and time downstream
        float N1 = 3;
        float X1 = 15;
 
        // Distance and time upstream
        float N2 = 2;
        float X2 = 5;
 
        // Rate of downstream and upstream
        float Rate_downstream = X1 / N1;
        float Rate_upstream = X2 / N2;
 
        Console.WriteLine(
            rate(Rate_downstream, Rate_upstream)
            + " Km/hr");
    }
}
 
// This code is contributed by Palak Gupta

Producción:

1.25  Km/hr

Complejidad de tiempo: O(1)

Espacio Auxiliar: O(1)
 

Publicación traducida automáticamente

Artículo escrito por kumar_satyam 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 *