L3_T1
unknown
c_cpp
3 years ago
1.1 kB
8
Indexable
#include <iostream>
#include <cmath>
using namespace std;
double ForProduct(double x, int n);
double WhileProduct(double x, int n);
double DoProduct(double x, int n);
int main()
{
double x;
int n;
while(true)
{
cout << "\nInput x, n"<< endl;
cin >> x >> n;
if(x > 0 && n > 0) break;
cout << "\nIncorrect input values!";
}
cout << "Result with for: " << ForProduct(x, n) << endl
<< "Result with while: " << WhileProduct(x, n) << endl
<< "Result with do-while: " << DoProduct(x, n) << endl;
return 0;
}
double ForProduct(double x, int n)
{
double product = 1;
for(int i = 1; i <= n; i++)
{
product *= pow(x, 3*n);
}
return product;
}
double WhileProduct(double x, int n)
{
double product = 1;
int i = 1;
while(i <= n)
{
product *= pow(x, 3*n);
i++;
}
return product;
}
double DoProduct(double x, int n)
{
double product = 1;
int i = 1;
do
{
product *= pow(x, 3*n);
i++;
}
while(i <= n);
return product;
}Editor is loading...