Wednesday, January 8, 2025
Google search engine
HomeData Modelling & AICalculate Work Done and Power Consumed by a particle

Calculate Work Done and Power Consumed by a particle

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




// C++ program to implement
// the above approach
#include <bits/stdc++.h>
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




<script>
 
// Javascript program to implement
// the above approach
 
// Function to calculate work done
function workDone(F, D)
{
     
    // Stores the work done
    var W;
    W = F * D;
 
    return W;
}
 
// Function to calculate power consumed
function power(F, D, T)
{
     
    // Stores the amount
    // of power consumed
    var P;
    P = (F * D) / T;
 
    return P;
}
 
// Driver code
var F = 100, D = 20, T = 100;
 
document.write(workDone(F, D) + "<br>");
document.write(power(F, D, T));
 
// This code is contributed by Khushboogoyal499
 
</script>


Output: 

2000
20

 

Time Complexity: O(1)
Auxiliary Space: O(1)

 

Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

RELATED ARTICLES

Most Popular

Recent Comments