{
? Int n=10;
? Int sum=0, CNT=0, avg=0;
? for (int i=1; i <=n; I++)
? If (I % 3==0)
? {
? Sum=sum + I;
? Cnt++;
? }? Avg=sum/CNT;
? Cout & lt;
CodePudding user response:
6. Change the code in the n to 2, CNT will be equal to zero; Zero divisorCodePudding user response:
Reference:# include
Int main ()
{
Int n=10;
Int sum=0, CNT=0, avg=0;
for (int i=1; i <=n; I++)
If (I % 3==0) {
Sum=sum + I;
Cnt++;
}
Avg=sum/CNT;
Cout & lt;<", the average is "& lt;
}
//within 10 integers have 3, can be divided exactly by 3 sum to 18, the average is 6
//within 12 can be divided exactly by 3 integers have four, sum to 30, average of 7
//within 20 integers can be divided exactly by 3 have 6, total was $63, average of 10
//4 5 lack of CNT value judgment, potential avg=sum/CNT; Will go wrong
//the code n 2, instead of CNT will be equal to zero, avg=sum/CNT; Error