#include <stdio.h>
int main() {
int a,b,sum=0;
scanf("%d%d",&a,&b);
for(int i=a;i<=b;i++)
sum+=i*i;
printf("%d",sum);
return 0;
}
//explain this :
In function 'main':
main.c:6:5: error: this 'for' clause does not guard... [-Werror=misleading-indentation]
6 | for(int i=a;i<=b;i++)
| ^~~
This code calculates the sum of squares of integers from a to b. It reads two integers, then loops through each number in that range, adding the square of each number to a running total, and finally prints the result.
The error occurs because the indentation suggests that the `printf` statement is part of the `for` loop, but in C, without curly braces `{}`, only the immediately following statement is inside the loop. The compiler warns that the indentation is misleading.
- The `for` loop currently only includes the `sum+=i*i;` line. The `printf` is outside the loop, but the indentation makes it look like it belongs inside.
- To include multiple statements in the loop, you need to enclose them in curly braces `{}`.