#include "stdio.h"
#include "stdlib.h"
#include "time.h"
int main()
{
printf("\n1");
srand ((unsigned)time(NULL));
printf("\n1");
struct node {
int Digi;
struct node *Prev;
struct node *Next;
};
printf("\n1");
struct node Num1, Num2, Num3, Num4, Num5, Num6, Num7, Num8, Num9, Num10,NumAdd;
Num1.Digi = rand() % 100;
Num1.Prev = NULL;
do {
Num2.Digi = rand() % 100;
} while ((Num2.Digi < Num1.Digi) || (Num2.Digi == Num1.Digi));
Num2.Prev = &Num1;
Num1.Next = &Num2;
do
Num3.Digi = rand() % 100;
while ((Num3.Digi < Num2.Digi) || (Num3.Digi == Num2.Digi));
Num3.Prev = &Num2;
Num2.Next = &Num3;
do
Num4.Digi = rand() % 100;
while ((Num4.Digi < Num3.Digi) || (Num4.Digi == Num3.Digi));
Num3.Prev = &Num4;
Num3.Next = &Num3;
do
Num5.Digi = rand() % 100;
while ((Num5.Digi < Num4.Digi) || (Num5.Digi == Num4.Digi));
Num5.Prev = &Num4;
Num4.Next = &Num5;
do
Num6.Digi = rand() % 100;
while ((Num6.Digi < Num5.Digi) || (Num6.Digi == Num5.Digi));
Num6.Prev = &Num5;
Num5.Next = &Num6;
do
Num7.Digi = rand() % 100;
while ((Num7.Digi < Num6.Digi) || (Num7.Digi == Num6.Digi));
Num7.Prev = &Num6;
Num6.Next = &Num7;
do
Num8.Digi = rand() % 100;
while ((Num8.Digi < Num7.Digi) || (Num8.Digi == Num7.Digi));
Num8.Prev = &Num7;
Num7.Next = &Num8;
do
Num9.Digi = rand() % 100;
while ((Num9.Digi < Num8.Digi) || (Num9.Digi == Num8.Digi));
Num8.Prev = &Num9;
Num9.Next = &Num8;
do
Num10.Digi = rand() % 100;
while ((Num10.Digi < Num9.Digi) || (Num10.Digi == Num9.Digi));
Num10.Prev = &Num9;
Num9.Next = &Num10;
Num10.Next = NULL;
printf("\n1");
printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
Num1.Digi, Num2.Digi, Num3.Digi, Num4.Digi, Num5.Digi,
Num6.Digi, Num7.Digi, Num8.Digi, Num9.Digi, Num10.Digi);
}
該程序很少運行到最後。但打印出2「1」後,它總是卡住。有時它會正確運行並顯示10個數字。但它最有可能被卡住了。我知道有一些循環,但它們不會導致程序停留很長時間。我們現在都有快速的電腦。那麼有誰知道它爲什麼會卡住?簡單的C程序卡住了
你的頭腦創造了[___MCVE___(http://stackoverflow.com/help/mcve)? –
你是否嘗試過使用調試器或在其中放置幾個'printf'來查看控制流的位置? –
爲什麼不在比較中使用'<='? –