使用switch语句或while循环,如何找到从-14到14的数字平方。我对应该如何开始感到困惑。
只需从-14上升到14:
for(int i = -14; i <= 14; i++)
{
printf("%d squared is %d\n", i, i * i);
}
while
循环:
int i = -14;
while(i <= 14)
{
printf("%d squared is %d\n", i, i * i);
i++;
}
switch
:
switch(0)
{
int i;
default:
i = -14;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
printf("%d squared is %d\n", i, i * i);
i++;
break;
}