The main ()
{
Int k, j, s;
For (k=2; K<6; K++ k++);
{s=1;
For (j=k; J<6; J++) s=s + j;
}
Printf (" s=% d, k=% d ", s, k);
}
CodePudding user response:
Because of the for () followed by a semicolon "; ',CodePudding user response:
Pick up points for reference:# include" stdio.h "
The main ()
{
Int k, j, s;
S=1;//setting a
For (k=2; K<6; K +=2)//for (k=2; K<6; K++ k++) two k++ equivalent to k=k + 2//; Many a semicolon
{
//s=1; The K cycle in every time buy 1
For (j=k; J<6; J++)
S=s + j;
}
Printf (" s=% d, k=% d ", s, k);
return 0;
}
CodePudding user response:
Follow up step by step:
# include "stdio.h"
The main ()
{
Int k, j, s;
For (k=2; K<6; K++ k++);
//the behind for a; So after perform the cycle, k=6
//may is meant the following this paragraph is the loop body, but as a result of what is said above for a semicolon at the end of the line, so what's happening with you think the difference is very big
{
S=1;
For (j=k; J<6; J++) s=s + j;//as a result of k=6, the circulation j<6, in the loop body is executed to
//this time there is no change in the value of s, still 1
}
Printf (" s=% d, k=% d ", s, k);
}
CodePudding user response:
Thank you