第一个代码为 1! 的 82!阶乘……有什么理由吗?考虑到 do 循环工作得非常好,这对我来说真的没有任何意义。如果您运行该程序,您将看到一个表格,其中给出了阶乘的所有答案。do循环是我必须做的,但我不能使用它。
知道为什么 for 循环不能正常工作吗?
#include <stdio.h> /* Necessary header */
#define LAST_NUMBER 25 /* Macro preset to avoid magic numbers */
int main(void) /* Start executive method */
{
int Nbr;
signed long total = Nbr;
printf("Nbr Nbr!"); /* Table Headers */
printf("\n----------------------");
for (Nbr = 1; Nbr<=LAST_NUMBER;) /* Loop statement begins */
{
total *= Nbr;
printf("\n%2d %15ld", Nbr, total);
Nbr++;
/* Prints both columns for table */
} /* Loop ends when predefined number is reached */
return 0;
} /* End main method */
/* The following code works fine */
#include <stdio.h> /* Necessary header */
#define LAST_NUMBER 25 /* Macro preset to avoid magic numbers */
int main(void) /* Start executive method */
{
int Nbr = 1;
signed long total = Nbr;
printf("Nbr Nbr!"); /* Table Headers */
printf("\n----------------------");
do /* Loop statement begins */
{
total *= Nbr;
printf("\n%2d %15ld", Nbr, total); /* Prints both columns for table */
Nbr++;
}while (Nbr<=LAST_NUMBER); /* Loop ends when predefined number is reached */
return 0;
} /* End main method */