The curly braces ({ and }) define the scope. So
if (i % 6==0)
{
printf("\nNumber %d can be divided with 6 ", i);
sum += i;
}
is the right code, as it says, when i can be divided by 6 without any remainders then we want to print and increase the sum. Without the curly braces, only the printing happens under this condition and the summation happens even if the condition is false (as it would be outside of the scope of the if statement).
I hope this helps.