📜  计算完成的功和粒子消耗的功率

📅  最后修改于: 2021-04-17 18:55:50             🧑  作者: Mango

给定三个整数F,DT分别表示作用在粒子上的力,粒子行进的位移和消耗的时间,任务是计算该粒子完成的功( W )和消耗的功率( P )。

例子:

方法:可以使用以下公式来解决问题,以计算完成的工作量和功耗:

下面是上述方法的实现:

C++14
// C++ program to implement
// the above approach
#include 
using namespace std;
 
// Function to calculate work done
float workDone(float F, float D)
{
    // Stores the work done
    float W;
    W = F * D;
 
    return W;
}
// Function to calculate power consumed
float power(float F, float D, float T)
{
    // Stores the amount
    // of power consumed
    float P;
    P = (F * D) / T;
 
    return P;
}
 
// Driver Code
int main()
{
    float F = 100, D = 20, T = 100;
 
    cout << workDone(F, D) << endl;
    cout << power(F, D, T) << endl;
 
    return 0;
}


Java
// Java program to implement
// the above approach
class GFG{
     
// Function to calculate work done
static float workDone(float F, float D)
{
     
    // Stores the work done
    float W;
    W = F * D;
 
    return W;
}
 
// Function to calculate power consumed
static float power(float F, float D, float T)
{
     
    // Stores the amount
    // of power consumed
    float P;
    P = (F * D) / T;
 
    return P;
}
 
// Driver code
public static void main(String[] args)
{
    float F = 100, D = 20, T = 100;
     
    System.out.println(workDone(F, D));
    System.out.println(power(F, D, T));
}
}
 
// This code is contributed by abhinavjain194


Python3
# Python3 program to implement
# the above approach
 
# Function to calculate work done
def workDone(F, D):
     
    return F * D
 
# Function to calculate power consumed
def power(F, D, T):
     
    return ((F * D) / T)
 
# Driver code
F = 100
D = 20
T = 100
 
print(workDone(F, D))
print(power(F, D, T))
 
# This code is contributed by abhinavjain194


C#
// C# program to implement
// the above approach
using System;
 
class GFG{
     
// Function to calculate work done
static float workDone(float F, float D)
{
     
    // Stores the work done
    float W;
    W = F * D;
 
    return W;
}
 
// Function to calculate power consumed
static float power(float F, float D, float T)
{
     
    // Stores the amount
    // of power consumed
    float P;
    P = (F * D) / T;
 
    return P;
}
 
// Driver code
static void Main()
{
    float F = 100, D = 20, T = 100;
     
    Console.WriteLine(workDone(F, D));
    Console.WriteLine(power(F, D, T));
}
}
 
// This code is contributed by abhinavjain194


Javascript


输出:
2000
20

时间复杂度: O(1)
辅助空间: O(1)