Is this the right way to see this program?
This is a set of nested for statements.
The program asks you to pick an integer "n" which based on the initializations of "i=1" & "j=1" must be positive for the loops to even execute.
I would say the outer for loop where "i = 1" executes n-1 times and I think the inner loop executes n-1 times as well.
The output "sum" counts the number of loops that are executed for both outer and inner for loops and then adds 1.
Is this correct?
Code:
{
int i,j,n, sum=0;
printf("Enter n \n");
scanf("%d",&n);
for (i=1; i<=n; i++)
{
for(j=1; j<=i; j++)
sum = sum +1;
}
printf("Sum = %d\n",sum);