-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay-39.cpp
42 lines (29 loc) · 1.51 KB
/
Day-39.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Ques 1. Imagine you are working on the development of a solar power calculator. The calculator needs to estimate how much solar energy can be generated over a certain period, assuming that the solar panels produce a specific amount of energy every day.
// You have the following parameters:
// x: The amount of energy (in kilowatt-hours) generated by the solar panels in one day.
// n: The number of days the solar panels will operate.
// Your task is to implement a function that calculates the total energy generated over n days. The formula to calculate the energy over multiple days is the power of x raised to n, i.e., x^n, where x is the daily energy production, and n is the number of days.
// Implement a function pow(x, n) that calculates x raised to the power of n (i.e., x^n).
// Example:
// Input:
// x = 2.00000 (the solar panels produce 2 kWh/day)
// n = 10 (over 10 days)
// Output:
// 1024.00000 kWh (the total energy produced over 10 days)
// Explanation:
// In this example, the panels produce 2 kWh per day, and you want to find out how much energy will be produced over 10 days. The answer is 2^10 = 1024 kWh, which is the total energy generated.
// Write a function to efficiently compute the result for large values of n as well.
#include <iostream>
#include<iomanip>
#include <cmath>
using namespace std;
double totalEnergyGenerated(double x, int n){
return pow(x,n);
}
int main(){
double x;
int n;
cin>>x>>n;
cout<<fixed<<setprecision(2) <<totalEnergyGenerated(x,n);
return 0;
}