+ 1

Find the sum of first ten natural number 1 2 3 ...10 but the I m getting error please help thanks u

#include <iostream> using namespace std; int main() { int n, total = 0; n = 1 ; while (n < = 10) { total + = n ; n + + ; } cout <<"sum of first ten natural number" << total ; return 0; }

19th Oct 2016, 7:17 PM
kevink mahadeo
kevink mahadeo - avatar
3 odpowiedzi
+ 2
You have to get rid of some of the spaces. n < = 10 should be, n <= 10 total + = n; should be, total += n; n + +; should be n++;
19th Oct 2016, 7:49 PM
Ted L
Ted L - avatar
+ 1
Let me try this out btw thanks you
19th Oct 2016, 8:02 PM
kevink mahadeo
kevink mahadeo - avatar
0
#include <iostream> using namespace std; int main() { int n, total=0; n = 1 ; while (n<=10) { total+=n ; n++; } cout <<"sum of first ten natural number" << total ; return 0; } to many space
19th Oct 2016, 7:52 PM
masuod