Find the value of the expression. Sample input: 2.4 -4.2 0.6 Sample output 4,726

In the course of doing something wrong. I have no idea how to count sigma. Please help, how should it be right?

enter image description here

#include <iostream> #include <cmath> #include <iomanip> using namespace std; int main() { double a,b,x,p,sum=0,n; cin >> a >> b >> x; n=10*x; for (int i=n;i<(-10*b);i++) { sum+=(pow((-1),(n+1))*pow(n,1.0/2.0))/(n*(n+2)); } p=b/2*x; p=cos(p)/sin(p); p=pow(p,3)*sum; p=p+pow((abs(1-x*exp(xb))),1.0/3.0); cout << fixed << setprecision(3) << p; return 0; } 
  • Sigma is considered through the cycle, and in your code it even seems to be there. Explain what the existing code does not suit you (I voted to reopen the issue, but without any explanations it risks being closed again) - andreymal
  • You do not have a here, why are you asking for it? - Ivan Triumphov 6:39 pm
  • @andreymal In my code, the value is 4.219, but it should be 4.726, when entering values ​​from the example. - Max
  • I rewrote the example. I got other values. You do not summarize the for loop. In the code that you gave in the question - Ivan Triumphov
  • And x cannot be between -1 <x <1. So how do you divide by zero where b / 2 * x - Ivan Triumphov

2 answers 2

The equation has a solution if b <0, x! = 0, 10 * x <-10 * b, 10 * x> 0 and -10 * b> 0

 #include <iostream> #include <cmath> #include <iomanip> #include <QDebug> using namespace std; double b,x; void cinB() { cin >> b; if (b>=0) { cout <<"Input b<0"; cin >> b ; } } void cinX() { cin>>x; if (x<=0) { cout <<"Input x>0"; cin >> x ; } } void cinXB () { if (10*x>=-10*b) { cout <<"It should be: 10*x<-10*b"; cinB(); cinX(); cinXB(); } } int main() { double P,sum=0; cinB(); cinX(); cinXB(); if (10*x<-10*b) { for (double n=10*x;n<(-10*b);n=n+1) { sum+=(pow((-1),(n+1))*pow(n,1/2))/(n*(n+2)); qDebug()<<sum<<n; } qDebug()<<"10*x<-10*b"<<sum; } P=pow((abs(1-x*exp(xb))),1/3)+cos(b/2*x)/sin(b/2*x)*sum; cout <<"P="<<P; return 0; } 

Your n must be non-zero and -2 otherwise the division by zero: enter image description here I did it, the value is 1.00373, if I enter b = -4.2, x = 0.6 enter image description here Maybe I made a mistake somewhere and someone will indicate where. And your "a" does not seem to be not involved in the calculations!

  • Three real numbers a (a> 0), b (b <0), x (-1 <x <1) are given in the input stream. The values ​​of the source data are chosen so that the expression makes sense. - Max
  • In the day off - things. number with an accuracy of 3 decimal places - Max
  • I tried to enter the values ​​from the example, displays the wrong answer - Max
  • one
    @Max after that. And where in the formula "a"? I do not understand? - Ivan Triumphov 8:19 pm
  • There are the same type of tasks, I brought the simplest to understand, then by increasing complexity. The main thing is to learn how to solve sigma - Max
 #include <iostream> #include <cmath> #include <iomanip> using namespace std; int main() { double a,b,x,p,sum=0,n; cin >> a >> b >> x; if ((10*x)<(-10*b)) { for (double n=10*x;n<=(-10*b);n++) { sum+=(pow((-1),(n+1))*pow(n,1.0/2.0))/(n*(n+2)); } } p=b/(2*x); p=cos(p)/sin(p); p=pow(p,3)*sum; p=pow((abs(1-x*exp(xb))),1.0/3.0)+p; cout << fixed << setprecision(3) << p; return 0; }