while(1) trong lập trình C có ý nghĩa là gì?

  1. #include

  2.  

    #include

  3.  

    #include

  4.  

    #include

  5.  

    #include

  6.  

    #include

  7.  # define MAX 100

  8.  typedef struct nhanvien

  9.     {

  10.         char manv[5];

  11.         char hoten[20];

  12.         char phai[4];

  13.     };

  14. typedef struct list1

  15.     {

  16.         int n;

  17.         nhanvien nodes[MAX];

  18.     };

  19. typedef struct vattu

  20.     {

  21.         char mavl[15];

  22.         char tenvl[20];

  23.     };

  24.  typedef struct list2

  25.  {

  26.    int n;

  27.    vattu nodes[MAX];

  28.  };

  29. typedef struct ngay

  30.     {

  31.         int ngay;

  32.         int thang;

  33.         int nam;

  34.     }NGAY;

  35. void nhapnv(nhanvien x)

  36. {

  37. printf(” nhap ma nhan vien : “);
  38. fflush(stdin);stdin
  39. gets(x.manv);x .
  40. printf(” nhap ho ten : “);
  41. fflush(stdin);stdin
  42. gets(x.hoten);x .
  43. fflush(stdin);stdin
  44. gets(x.phai);x .
  45. }

  46. void xuatnv(nhanvien x)

  47. {

  48. printf(

    “Ma nhan vien:%s\ n”

    ,x.manv);x .

  49. printf(

    “ho ten nhan vien:%s\ n”

    ,x.hoten);x .

  50. printf(

    “phai:%s\ n”

    ,x.phai);x .

  51. }

  52. void nhapmangnv(list1 vàds)

  53. {

  54.   clrscr();

  55.   textcolor(0);

  56.   textbackground(15);

  57. printf(

    “\ nnhap so nhan vien:”

    );

  58. scanf(” % d “, vàds.n);ds .
  59.   for(int i=0;i

  60.    {

  61. printf(

    “nhap nhan vien  thu %d:\ n\ t”

    ,i+1);

  62. fflush(stdin);stdin
  63. printf(

    “\ n\ tnhap ma nhan vien:”

    );

  64. fflush(stdin);stdin
  65. gets(ds.nodes[i].manv);ds .
  66. printf(

    “\ n\ tnhap ho ten:”

    );

  67. fflush(stdin);stdin
  68. gets(ds.nodes[i].hoten);ds .
  69. fflush(stdin);stdin
  70. gets(ds.nodes[i].phai);ds .
  71.    }

  72. }

  73. void xuatmangnv(list1 vàds)

  74. {

  75.    clrscr();

  76.    textcolor(0);

  77.    textbackground(15);

  78.    for(int i=0;i

  79.    {

  80. printf(

    “manv:%s\ n”

    ,ds.nodes[i].manv);ds .

  81. printf(

    “hoten:%s\ n”

    ,ds.nodes[i].hoten);ds .

  82. printf(

    “phai:%s \ n”

    ,ds.nodes[i].phai);ds .

  83.    }

  84. }

  85. void nhapvt(list2 vàdsvt)

  86. {

  87.   clrscr();

  88.   textcolor(0);

  89.   textbackground(15);

  90. printf(” nhap so loai vat tu : “);
  91. scanf(” % d “, vàdsvt.n);dsvt .
  92.   for(int i=0;i

  93.   {

  94. printf(

    “nhap vat lieu thu %d\ n\ t”

    ,i+1);

  95. printf(” nhap ma vat lieu : “);
  96. fflush(stdin);stdin
  97. gets(dsvt.nodes[i].mavl);dsvt .
  98. fflush(stdin);stdin
  99. printf(

    “\ n\ tnhap ten vat lieu:”

    );

  100. gets(dsvt.nodes[i].tenvl);dsvt .
  101.        }

  102. }

  103. void xuatvt(list2 vàdsvt)

  104. {

  105.   clrscr();

  106.   textcolor(0);

  107.   textbackground(15);

  108.   for(int i=0;i

  109.   {

  110. printf(

    “ma vat lieu:%s\ n”

    ,dsvt.nodes[i].mavl);dsvt .

  111. fflush(stdin);stdin
  112. printf(” ten vat lieu : % s “,dsvt.nodes[i].tenvl);dsvt .
  113.   }

  114. }

  115. / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /

  116.   int namnhuan(NGAY vàx)

  117.   {

  118.     if(x.nam%400= =0 | |  (x.nam%4= =0và vàx.nam%100! =0))

  119.     return 1;

  120.     return 0;

  121.   }

  122.   int ktngay(NGAY x)

  123.   {

  124.       switch(x.thang)

  125.       {

  126.     case 1:

  127.     case 3:

  128.     case 5:

  129.     case 7:

  130.     case 8:

  131.     case 10:

  132.     case 12:

  133.         {

  134.         return 31;

  135.        

    }

  136.     case 4:

  137.     case 6:

  138.     case 9:

  139.     case 11:

  140.     {

  141.          return 30;

  142.          }

  143.     case 2:

  144.     {

  145.     if(namnhuan(x)= =1)

  146.               return 29;

  147.               else

  148.               return 28;

  149.               }

  150.       }

  151.   }

  152.   int kt(NGAY x)

  153.   {

  154.     if(x.thang> =1 và và x.thang< =12 và và x.nam> =2000)

  155.     {

  156.       if(x.ngay> =1 và và x.ngay< =ktngay(x))

  157.       return 1;

  158.       else

  159.       return 0;

  160.     }

  161.     return 0;

  162.   }

  163.   void nhapngay(NGAY x)

  164.   {

  165.     do

  166.     {

  167. scanf(” % d “, vàx.ngay);x .
  168. scanf(” % d “, vàx.thang);x .
  169. scanf(” % d “, vàx.nam);x .
  170.     }while(kt(x)! =1);

  171.   }

  172.   void xuatngay(NGAY x)

  173.   {

  174. printf(” ngay % d thang % d nam % d “,x.ngay,x.thang,x.nam);x. x. x .
  175.   }

  176. / * * * * * * * * * *

  177. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /

  178.   typedef struct hoadon

  179.   {

  180.     char sohd[5];

  181.     NGAY ngay;

  182.     char loai[5];

  183.     nhanvien manv;

  184.   };

  185.   typedef struct node

  186.   {

  187.    hoadon info;

  188.    struct node*next;

  189.   };

  190.     typedef struct node* PTR;

  191.     void khoitao(PTR vàFirst)

  192.     {

  193.      First=NULL;

  194.     }

  195.     PTR new_node()

  196.     {

  197.      PTR p;

  198. =(PTR)malloc(sizeof(struct node));PTRnode
  199.      return (p);

  200.     }

  201.     void khoitao1(PTR vàFirst)

  202.     {

  203.      First=NULL;

  204.     }

  205.     int ktloai(char *s)

  206.     {

  207.      char *loai=strdup(s);

  208. int n=strlen(loai);loai
  209.      for(int i=0;i

  210.        if(loai[i]= =’ N ‘| | loai[i]= =’ X ‘)

  211.      return 1;

  212.      return 0;

  213.     }

  214.     void insert_last(PTR vàFirst,hoadon x)

  215.     {

  216.     PTR p=new_node();

  217.     p->info=x;

  218.     p->next=NULL;

  219.     if(First= =NULL)

  220.       First=p;

  221.       else

  222.       {

  223.         for(PTR last=First;last->next! =NULL;last=last->next);

  224.         last->next=p;

  225.       }

  226.     }

  227.     void nhaphd(hoadon x)

  228.     {

  229. printf(” nhap so hoa don : “);
  230. fflush(stdin);stdin
  231. gets(x.sohd);x .
  232.       nhapngay(x.ngay);

  233.       do

  234.       {

  235. printf(” nhap loai hoa don : “);
  236. scanf(” % s “, vàx.loai);x .
  237.       }while(ktloai(x.loai)! =1);

  238.        nhapnv(x.manv);

  239.        }

  240.        void xuathd(hoadon x)

  241.        {

  242. printf(” so hoa don : % s “,x.sohd);x .
  243. printf(” ngay lap hoa don : “);
  244.     xuatngay(x.ngay);

  245. printf(” loai hoa don : % s “,x.loai);x .
  246. printf(” nhan vien lap hoa don : “);
  247.     xuatnv(x.manv);

  248.        }

  249.        void nhapdshd(PTR và First)

  250.        {

  251.      clrscr();

  252.      textcolor(0);

  253.      textbackground(15);

  254. printf(” lap hoa don ( nhan 0 ket thuc ) “);
  255.     int  stt=1;

  256.      hoadon x;

  257.       / / x.sohd = 0 ;

  258.      while(1)

  259.      {

  260. printf(” nhap hoa don thu % d “,stt);stt
  261. printf(” nhap so hoa don : “);
  262. fflush(stdin);stdin
  263. gets(x.sohd);x .
  264.      nhapngay(x.ngay);

  265.      do

  266.      {

  267. printf(” nhap loai hoa don : “);
  268. scanf(” % s “, vàx.loai);x .
  269.      }while(ktloai(x.loai)! =1);

  270.      nhapnv(x.manv);

  271.      insert_last(First,x);

  272.      stt+ + ;

  273.      }

  274.        }

  275. / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /

  276. void main()

  277. {

  278. NGAY x;

  279.  list1 ds;

  280.  list2 dsvt;

  281. / / nhapmangnv ( ds ) ;

  282. / / xuatmangnv ( ds ) ;

  283. / / nhapvt ( dsvt ) ;

  284. / / xuatvt ( dsvt ) ;

  285. / / nhapngay ( x ) ;

  286.    PTR dshd;

  287.    khoitao1(dshd);

  288.    nhapdshd(dshd);

  289.  getch(

    )

    ;

  290. }

Source: https://bem2.vn
Category: TỔNG HỢP

Rate this post
Xem thêm  Hướng dẫn cách sao lưu tin nhắn trên Android dễ làm

Bài viết liên quan

Để lại ý kiến của bạn:

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *