+ 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; }
3 Respuestas
+ 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++;
+ 1
Let me try this out btw thanks you
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