Programa para calcular Energía Cinética y Energía Potencial

Dados tres valores flotantes M , H y V que representan la masa, la velocidad y la altura de un objeto, respectivamente, la tarea es calcular su energía cinética y su energía potencial
Nota: el valor de la aceleración debida a la gravedad (g) es 9.8 e ignore las unidades.   

Ejemplos:

Entrada: M = 25, H = 10, V = 15
Salida:
Energía cinética = 2812,5
Energía potencial = 2450
Explicación: la energía cinética de la partícula es 2812,5 y la energía potencial es 2450.

Entrada : M=5.5, H=23.5, V= 10.5
Salida :
303.188
1266.65

 

Enfoque: Los valores requeridos de energía cinética y energía potencial se pueden calcular utilizando las dos fórmulas siguientes:

Energía Cinética = 0.5 * Masa ( M ) * Velocidad ( V ) 2 

Energía potencial = Masa (M) * Altura (H) * Aceleración debida a la gravedad (g)

A continuación se muestra la implementación del enfoque anterior:

C++14

// C++ Program to implement
// the above approach
 
#include <bits/stdc++.h>
using namespace std;
 
// Function to calculate Kinetic Energy
float kineticEnergy(float M, float V)
{
    // Stores the Kinetic Energy
    float KineticEnergy;
 
    KineticEnergy = 0.5 * M * V * V;
 
    return KineticEnergy;
}
 
// Function to calculate Potential Energy
float potentialEnergy(float M, float H)
{
    // Stores the Potential Energy
    float PotentialEnergy;
 
    PotentialEnergy = M * 9.8 * H;
 
    return PotentialEnergy;
}
 
// Driver Code
int main()
{
    float M = 5.5, H = 23.5, V = 10.5;
 
    cout << "Kinetic Energy = "
         << kineticEnergy(M, V) << endl;
    cout << "Potential Energy = "
         << potentialEnergy(M, H) << endl;
    return 0;
}

Java

// Java program to implement
// the above approach
class GFG{
  
// Function to calculate Kinetic Energy
static double kineticEnergy(double M, double V)
{
     
    // Stores the Kinetic Energy
    double KineticEnergy;
 
    KineticEnergy = 0.5 * M * V * V;
 
    return KineticEnergy;
}
 
// Function to calculate Potential Energy
static double potentialEnergy(double M, double H)
{
     
    // Stores the Potential Energy
    double PotentialEnergy;
 
    PotentialEnergy = M * 9.8 * H;
 
    return PotentialEnergy;
}
 
// Driver Code
public static void main(String []args)
{
    double M = 5.5, H = 23.5, V = 10.5;
 
    System.out.println("Kinetic Energy = " +
                       kineticEnergy(M, V));
    System.out.println("Potential Energy = " +
                       potentialEnergy(M, H));
}
}
 
// This code is contributed by AnkThon

Python3

# Python3 program to implement
# the above approach
 
# Function to calculate Kinetic Energy
def kineticEnergy(M, V):
 
    # Stores the Kinetic Energy
    KineticEnergy = 0.5 * M * V * V
 
    return KineticEnergy
 
# Function to calculate Potential Energy
def potentialEnergy(M, H):
 
    # Stores the Potential Energy
    PotentialEnergy = M * 9.8 * H
 
    return PotentialEnergy
 
# Driver Code
if __name__ ==  "__main__":
 
    M = 5.5
    H = 23.5
    V = 10.5
 
    print("Kinetic Energy = ", kineticEnergy(M, V))
    print("Potential Energy = ", potentialEnergy(M, H))
     
# This code is contributed by AnkThon

C#

// C# program to implement
// the above approach
using System;
using System.Collections.Generic;
 
class GFG{
  
/// Function to calculate Kinetic Energy
static double kineticEnergy(double M, double V)
{
     
    // Stores the Kinetic Energy
    double KineticEnergy;
 
    KineticEnergy = 0.5 * M * V * V;
 
    return KineticEnergy;
}
 
// Function to calculate Potential Energy
static double potentialEnergy(double M, double H)
{
     
    // Stores the Potential Energy
    double PotentialEnergy;
 
    PotentialEnergy = M * 9.8 * H;
 
    return PotentialEnergy;
}
 
// Driver Code
public static void Main()
{
    double M = 5.5, H = 23.5, V = 10.5;
 
    Console.WriteLine("Kinetic Energy = " +
                      kineticEnergy(M, V));
    Console.Write("Potential Energy = " +
                  potentialEnergy(M, H));
}
}
 
// This code is contributed by bgangwar59

Javascript

<script>
 
      // Javascript program for the above approach
 
      // Function to calculate Kinetic Energy
        function kineticEnergy(M, V)
        {
          // Stores the Kinetic Energy
            let KineticEnergy;
 
            KineticEnergy = 0.5 * M * V * V;
 
            return KineticEnergy;
        }
 
        // Function to calculate Potential Energy
        function potentialEnergy(M, H) {
            // Stores the Potential Energy
            let PotentialEnergy;
 
            PotentialEnergy = M * 9.8 * H;
 
            return PotentialEnergy;
        }
 
        // Driver Code
 
        let M = 5.5, H = 23.5, V = 10.5;
 
        document.write("Kinetic Energy = "
            + kineticEnergy(M, V))
         
        document.write("<br>");
         
        document.write( "Potential Energy = "
            + potentialEnergy(M, H))
 
        // This code is contributed by Hritik
         
 </script>
Producción: 

Kinetic Energy = 303.188
Potential Energy = 1266.65

 

Tiempo Complejidad: O(1)
Espacio Auxiliar: O(1)

Publicación traducida automáticamente

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