0
code problem
//find the sum of the series 1 +11 + 111 + 1111 + .. n terms #include <iostream> #include <cmath> using namespace std; int main() { //Getting user input int x,sum,n; x=0;sum=0; cout<<"Enter the number of terms you wanna add"<<endl; cin>>n; //LOOP for (int i=0; i<n; i++){ x += pow(10,i); sum += x; } cout<<"Sum is: "<<sum<<endl; return 0; } I cannot get the right output after the third term. what is the problem in the code?
8 Answers
+ 2
I got 122
+ 2
working.. thank you everyone....
I think I have missed something
+ 1
But from third term it gives incorrect outputs
+ 1
I ll check it
0
Huh I ran your code and it actually works...
0
Your code gives me 123 for the third term, isn't that right ?
0
I just copy-pasted your code, that's not normal đ
0
No problem đ