Calculate Work Done and Power Consumed by a particle
Last Updated :
13 Apr, 2021
Given three integers F, D, and T representing the force acting on a particle, displacement traveled by the particle, and time consumed respectively, the task is to calculate Work done (W) and Power consumed (P) by that particle.
Examples:
Input: F = 100, D = 20, T = 100
Output:
Work done: 2000
Power Consumed: 200
Input : F=40.2, D=10.6, T=20
Output :
Work Done: 426.12
Power Consumed: 21.306
Approach: The problem can be solved using the following formulas to calculate Work done and Power consumed:
Work done (W) = Force acting on particle (F) * Displacement of Particle (D)
Power Consumed (P) = Force acting on particle (F) * Displacement of Particle (D) / Time consumed (T)
Below is the implementation of the above approach:
C++14
#include <bits/stdc++.h>
using namespace std;
float workDone( float F, float D)
{
float W;
W = F * D;
return W;
}
float power( float F, float D, float T)
{
float P;
P = (F * D) / T;
return P;
}
int main()
{
float F = 100, D = 20, T = 100;
cout << workDone(F, D) << endl;
cout << power(F, D, T) << endl;
return 0;
}
|
Java
class GFG{
static float workDone( float F, float D)
{
float W;
W = F * D;
return W;
}
static float power( float F, float D, float T)
{
float P;
P = (F * D) / T;
return P;
}
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));
}
}
|
Python3
def workDone(F, D):
return F * D
def power(F, D, T):
return ((F * D) / T)
F = 100
D = 20
T = 100
print (workDone(F, D))
print (power(F, D, T))
|
C#
using System;
class GFG{
static float workDone( float F, float D)
{
float W;
W = F * D;
return W;
}
static float power( float F, float D, float T)
{
float P;
P = (F * D) / T;
return P;
}
static void Main()
{
float F = 100, D = 20, T = 100;
Console.WriteLine(workDone(F, D));
Console.WriteLine(power(F, D, T));
}
}
|
Javascript
<script>
function workDone(F, D)
{
var W;
W = F * D;
return W;
}
function power(F, D, T)
{
var P;
P = (F * D) / T;
return P;
}
var F = 100, D = 20, T = 100;
document.write(workDone(F, D) + "<br>" );
document.write(power(F, D, T));
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...