I'm going to print the sigma from n=30 , i=1 ( i²+1) so can you help me to find my mistake | Sololearn: Learn to code for FREE!
0

I'm going to print the sigma from n=30 , i=1 ( i²+1) so can you help me to find my mistake

#include <iostream> #include <cmath> using namespace std; int main(){ int n=0; int sum=0; int i=1; do{ cout<<"this program will calculate the sum of (i^2+1) , where i goes from 1 to n"<<endl; cout<<"Enter the value for n:"<<endl; cin>>n; for(i=1;i<=30;i++){ sum=sum+1; sum=pow(i,2)+1; } cout<<"the sum is "<<sum; }while(0); return 0; }

13th May 2020, 9:39 AM
Dostonbek
Dostonbek - avatar
1 Odpowiedź
+ 1
You want find sigma (i^2+1), then why are you increasing sum by one....
14th May 2020, 7:52 AM
DeWill
DeWill - avatar