I wonder how many times the 2 piece of code will be executed. Both of them are n times or one of them is n+1 ?
int sum=0;
for (int i = 1; i <= n; i++)
sum = sum + i;
AND
int sum=0;
for (int i = 1; i <= n; ++i)
sum = sum + i;
Is there anyone to help me ?
EDIT Sınce I got so many , bad comment. I decided to give my real intent to ask this.
int sum = 0;
for (int i = 1; i <= n; ++i)
sum = sum + f1(i, n);}
int f1(int x, int n) {
int sum = 0;
for (int i = 1; i <= n; i++)
sum = sum + i;
return (x + sum); }
The exact complexity of this code snippet is O(n*(n+1)) and I want to learn why there is(n+1) instead of o(n*n)