Reputation: 39
int main()
{
int n, i, sum;
cout << "Enter a value for n: ";
cin >> n;
sum = 0;
i = 1;
do
{
sum += i * i;
i++;
}while (i <= n);
cout << "The sum of the first " << n
<< " numbers is " << sum << endl;
return 0;
}
whenever I run this code and use 4 as an example the output comes up as 30. When the factorial of 4 is 24
Upvotes: 0
Views: 106