What is the running time of the following piece of code ?

int sum=0,a=0,i=0;
while(i<n)
{
     a=0;
     while(a<i)
     {
          sum++;
          a++;
     }
     i++;
}


Difficulty level
This exercise is mostly suitable for students
n*n

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Printing a sequence of instructions on a machine with 1 register and 6 instructions