@Lvhau_1529/

Learn C

C

No description

fork
loading
Files
  • main.c
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

//Xoa lenh nay voi cac bai da co san!!!
int main(void)

/* //KTLT_1_10_Hephuongtrinh.c
{
    float a1,b1,c1,a2,b2,c2,d,dx,dy,x,y;
    printf("Nhap cac he so cua phuong trinh thu nhat:\n");
    printf("a1 = "); scanf("%f",&a1);
    printf("b1 = "); scanf("%f",&b1);
    printf("c1 = "); scanf("%f",&c1);
    printf("Nhap cac he so cua phuong trinh thu hai:\n");
    printf("a2 = "); scanf("%f",&a2);
    printf("b2 = "); scanf("%f",&b2);
    printf("c2 = "); scanf("%f",&c2);
    d=a1*b2-a2*b1;
    dx=c1*b2-c2*b1;
    dy=a1*c2-a2*c1;
    if(d!=0)
    {
            x=dx/d;
            y=dy/d;
            printf("He phuong trinh co nghiem duy nhat: x = %.2f, y = %.2f",x,y);
    }
else if((dx==0) && (dy==0))
            printf("He phuong trinh co vo so nghiem!");
      else printf("He phuong trinh vo nghiem!");
return 0;
}
*/

/*KTLT_1_5_Kiemtrasochinhphuong.c
{
    int n;
    printf("Nhap so nguyen duong n = "); scanf("%d",&n);
    if (sqrt(n) == (int)sqrt(n))
    printf("%d la so chinh phuong!",n);
    else printf("%d khong phai la so chinh phuong!",n);
    return 0;
}
*/
/*KTLT_2_2.c
{
    int n,k,i;
    long q,gt=1;
    float s=0;
    printf("Nhap k = ");
    scanf("%d",&k);
    for(i=1;i<=k;i++)
            s+=1.0/(2*i);
    printf("Tong S = %.2f",s);
    printf("\nNhap n = ");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        {
            gt*=i;
            q+=i*gt;
        }
    printf("Tong Q = %ld",q);
    return 0;
}
*/

/*KTLT_2_4
{
    int i,n,dem=0;
    printf("Nhap so nguyen duong n = "); scanf("%d",&n);
    printf("Cac so chinh phuong <%d la:\n",n);
    for(i=1;i<n;i++)
        if (sqrt(i) == (int)sqrt(i))
            {
                printf("\t%d",i);
                dem++;
            }
    printf("\nSo luong cac so chinh phuong <%d la: %d",n,dem);
    return 0;
}
*/

/*KTLT_2_5
{
  int a,b;
  printf("Nhap a = ");
  scanf("%d",&a);
  printf("Nhap b = ");
  scanf("%d",&b);
  while (a!=b)
    if (a>b) a=a-b;
    else b=b-a;
  printf("Uoc chung lon nhat la: %d",a);
  return 0;
}
*/

/*KTLT_2_6
{
  int a,b,x,y;
  printf("Nhap a = ");
  scanf("%d",&a);
  printf("Nhap b = ");
  scanf("%d",&b);
  x=a;y=b;
  while (x!=y)
    if (x>y) x=x-y;
    else y=y-x;
  printf("Dang toi gian cua phan so %d/%d la: %d/%d",a,b,a/x,b/x);
  return 0;
}
*/

/*KTLT_2_8
int nguyento(int n);
int main(void)
  {
    nt i,j,n;
    printf("Nhap so nguyen n = ");
    scanf("%d",&n);
    printf("Cac so nguyen to < %d la:\n",n);
    for(i=2;i<n;i++)
      if(nguyento(i)) printf("%d   ",i);
    return 0;
  }
int nguyento(int n)
  {
    int i;
    for(i=2;i<=n-1;i++)
      if(n%i==0) return 0;
    return 1;
  }
*/

/*KTLT_2_9
{
    int i,j,k;
    printf("Cac phuong an:\n");
    for(i=0;i<=50;i++)
            for(j=0;j<=25;j++)
                    for(k=0;k<=10;k++)
                            if(i+2*j+5*k==50) printf("(%d,%d,%d) ",i,j,k);
    return 0;
}
*/

/*KTLT_3_2_c
int dandau(int *a,int n);
int csc(int *a,int n);
int main (void)
{
    int *a,i,n;
    printf("Nhap so phan tu n = ");
    scanf("%d",&n);
    a=(int*)calloc(n,sizeof(int));
    for(i=0;i<n;i++)
            {
                    printf("a[%d] = ",i);
                    scanf("%d",&a[i]);
            }
    if (dandau(a,n)) printf("Day vua nhap la day dan dau");
    else printf("Day vua nhap khong phai la day dan dau");
    if (csc(a,n)) printf("\nDay vua nhap la cap so cong");
    else printf("\nDay vua nhap khong phai la cap so cong");
    free(a);
    a=NULL;
    return 0;
}
int dandau(int *a,int n)
{
    int i;
    for(i=0;i<n-1;i++)
            if (a[i]*a[i+1]>=0) return 0;
    return 1;
}
int csc(int *a,int n)
{
    int i,d;
    d=a[1]-a[0];
    for(i=1;i<n-1;i++)
            if (a[i+1]-a[i]!=d) return 0;
    return 1;
}
*/

/*KTLT_3_3_a_Chenphantu
void chen(int *a,int n,int x,int m);
int main (void)
        {
                int *a,i,n,x,m;
                printf("Nhap so phan tu n = ");
                scanf("%d",&n);
                a=(int*)calloc(n,sizeof(int));
                for(i=0;i<n;i++)
                        {
                                printf("a[%d] = ",i);
                                scanf("%d",&a[i]);
                        }
                printf("Nhap gia tri can chen x = ");
                scanf("%d",&x);
                printf("Nhap vi tri can chen m = ");
                scanf("%d",&m);
                chen(a,n,x,m);
                n++;
                printf("Day sau khi chen them gia tri %d vao vi tri %d la:\n",x,m);
                for(i=0;i<n;i++) printf("%d   ",a[i]);
                free(a);
                a=NULL;
                return 0;
        }
void chen(int *a,int n,int x,int m)
        {
                int i;
                realloc(a,sizeof(int)*(n+1));
                for(i=n;i>=m;i--)
                        a[i]=a[i-1];
                a[m-1]=x;
        }
*/

/*KTLT_3_3_c_Xoaphantu
void xoa(int *a,int n,int q);
int main (void)
        {
                int *a,i,n,m;
                printf("Nhap so phan tu n = ");
                scanf("%d",&n);
                a=(int*)calloc(n,sizeof(int));
                for(i=0;i<n;i++)
                        {
                                printf("a[%d] = ",i);
                                scanf("%d",&a[i]);
                        }
                printf("Nhap vi tri can xoa m = ");
                scanf("%d",&m);
                xoa(a,n,m);
                n--;
                printf("Day sau khi xoa di gia tri o vi tri %d la:\n",m);
                for(i=0;i<n;i++) printf("%d   ",a[i]);
                free(a);
                a=NULL;
                return 0;
        }
void xoa(int *a,int n,int m)
        {
                int i;
                for(i=m-1;i<n-1;i++)
                        a[i]=a[i+1];
                realloc(a,sizeof(int)*(n-1));
        }
*/

/*KTLT_3_4_a_Loaiphantutrung
void loaiphantutrung(int *a,int *n);
int main(void)
        {
                int *a,i,n;
                printf("Nhap so phan tu n = ");
                scanf("%d",&n);
                a=(int*)calloc(n,sizeof(int));
                for(i=0;i<n;i++)
                  {
                    printf("a[%d] = ",i);
                    scanf("%d",&a[i]);
                  }
                loaiphantutrung(a,&n);
                printf("So luong phan tu moi la: %d\n",n);
                printf("Day sau khi loai bo cac phan tu trung:\n");
                for(i=0;i<n;i++)
                    printf("%d   ",a[i]);
                free(a);
                a=NULL;
                return 0;
        }
void loaiphantutrung(int *a,int *n)
{
    int i,j,kt;
    for(i=1;i<*n;i++)
        {
          //Kiem tra a[i] co trung voi phan tu a[j] (j=0..i-1) khong
            kt=0;
            for(j=0;j<i;j++)
                if(a[j]==a[i])
                    {
                      kt=1;
                      break;
                    }
            // Neu a[i] trung voi a[j] nao do, can xoa a[i]
            if(kt)
                {
                    for(j=i;j<*n-1;j++)
                    [j]=a[j+1];
                    i--;
                    (*n)--;
                }
        }
}
*/

/*KTLT_3_4_b_Xapxepday
void sapxepday(int *a, int n);
int main(void)
{
    int *a,n,i;
    printf("Nhap so phan tu n = ");
    scanf("%d",&n);
    a=(int*)calloc(n,sizeof(int));
    for(i=0;i<n;i++)
        {
            printf("a[%d] = ",i);
            scanf("%d",&a[i]);
        }
    sapxepday(a,n);
    printf("Day sau khi sap xep la:\n");
    for(i=0;i<n;i++) printf("%d   ",a[i]);
    free(a);
    a=NULL;
    return 0;
}
void sapxepday(int *a, int n)
{
    int temp,i,j;
    for(i=0;i<n-1;i++)
        for(j=i+1;j<n;j++)
            if (a[j]<a[i])
                {
                    temp=a[i];
                    a[i]=a[j];
                    a[j]=temp;
                }
}
*/

/*KTLT_3_Mang2chieu_1_a
        {
                int a[20][30],i,j,m,n;
                float s=0,tb;
                printf("Nhap so dong m = ");scanf("%d",&m);
                printf("Nhap so cot n = ");scanf("%d",&n);
                for(i=0;i<m;i++)
                        for(j=0;j<n;j++)
                                {
                                        printf("a[%d][%d] = ",i,j);
                                        scanf("%d",&a[i][j]);
                                }
                for(i=0;i<m;i++)
                        for(j=0;j<n;j++)
                                s+=a[i][j];
                tb=s/(m*n);
                printf("Ma tran da nhap:\n");
                for(i=0;i<m;i++)
                        {
                                for(j=0;j<n;j++)
                                        printf("\t%d",a[i][j]);
                                printf("\n");
                        }
                printf("Tong cac phan tu = %.2f, trung binh cong = %.2f.",s,tb);
                return 0;
        }
*/

/*KTLT_3_2_Mang2chieu_2_a
        {
                int a[20][30],i,j,n,kt=1;
                printf("Nhap kich thuoc n = ");scanf("%d",&n);
                for(i=0;i<n;i++)
                        for(j=0;j<n;j++)
                                {
                                        printf("a[%d][%d] = ",i,j);
                                        scanf("%d",&a[i][j]);
                                }
                printf("Ma tran vuong da nhap:\n");
                for(i=0;i<n;i++)
                        {
                                for(j=0;j<n;j++)
                                        printf("\t%d",a[i][j]);
                                printf("\n");
                        }
                for(i=0;i<n;i++)
                        for(j=0;j<n;j++)
                                if((i==j && a[i][j]!=1)||(i!=j && a[i][j]!=0))
                                        {
                                                kt=0;
                                                goto tiep;
                                        }
                tiep:   if(kt) printf("Day la ma tran don vi!");
                                else printf("Day khong phai la ma tran don vi!");
                return 0;
        }
*/

/* KTLT_3_2_Mang2chieu_2_b
        {
                int a[20][30],i,j,n,kt=1;
                printf("Nhap kich thuoc ma tran n = ");scanf("%d",&n);
                for(i=0;i<n;i++)
                        for(j=0;j<n;j++)
                                {
                                        printf("a[%d][%d] = ",i,j);
                                        scanf("%d",&a[i][j]);
                                }
                for(i=0;i<n;i++)
                        for(j=i+1;j<n;j++)
                                        if (a[i][j]!=a[j][i])
                                                {
                                                        kt=0;
                                                        goto tiep;
                                                }
                tiep: printf("Ma tran da nhap:\n");
                for(i=0;i<n;i++)
                        {
                                for(j=0;j<n;j++)
                                        printf("%-6d",a[i][j]);
                                printf("\n");
                        }
                if(kt) printf("Day la ma tran doi xung!");
                else printf("Day khong phai la ma tran doi xung!");
                return 0;
        }
*/

/*KTLT_3_Xaukytu
        {
                char s[30],sdao[30];
                int i,n,kt=1;
                printf("Nhap xau: ");
                __fpurge(stdin);
                gets(s);
                n=strlen(s);
                for(i=0;i<=n/2-1;i++)
                        if(s[i]!=s[n-i-1])
                                {kt=0;break;}
                if(kt) printf("Xau doi xung!");
                else
                        {
                                printf("Xau khong doi xung!");
                                for(i=0;i<n;i++)
                                        sdao[i]=s[n-i-1];
                                sdao[n]='\0';
                                printf("Xau dao la: %s",sdao);
                return 0;
        }
*/

/*KTLT_4_5_Dientich_chuvi_hinhphang
void tamgiac(void);
void chunhat(void);
void hinhtron(void);
int main()
        {
                int chon;
                do
                        {
                                printf("\nCHUONG TRINH TINH DIEN TICH, CHU VI HINH PHANG");
                                printf("\nPhim 1: Hinh tam giac\nPhim 2: Hinh chu nhat\nPhim 3: Hinh tron\nPhim 4: Thoat\nMoi ban nhan phim: ");
                                scanf("%d",&chon);
                                if(chon==1) tamgiac();
                                else if(chon==2) chunhat();
                                else if(chon==3) hinhtron();
                        }
                while (chon!=4);
                return 0;
        }
void tamgiac(void)
        {
                float a,b,c,dt,p,cv;
                printf("Ban da chon Hinh tam giac!\n");
                printf("Nhap do dai 3 canh:\n");
                printf("a = ");
                scanf("%f",&a);
                printf("b = ");
                scanf("%f",&b);
                printf("c = ");
                scanf("%f",&c);
                cv=a+b+c;
                p=cv/2;
                dt=sqrt(p*(p-a)*(p-b)*(p-c));
                printf("Dien tich = %.2f. Chu vi = %.2f",dt,cv);
        }
void chunhat(void)
        {
                float a,b,dt,cv;
                printf("Ban da chon Hinh chu nhat\n");
                printf("Nhap chieu dai: a = ");
                scanf("%f",&a);
                printf("Nhap chieu rong: b = ");
                scanf("%f",&b);
                dt=a*b;
                cv=(a+b)*2;
                printf("Dien tich = %.2f. Chu vi = %.2f",dt,cv);
        }
void hinhtron(void)
        {
                float r,dt,cv;
                printf("Ban da chon Hinh tron\n");
                printf("Nhap ban kinh: r = ");
                scanf("%f",&r);
                dt=3.14*r*r;
                cv=2*3.14*r;
                printf("Dien tich = %.2f. Chu vi = %.2f",dt,cv);
        }
*/

/*KTLT_4_6_Tinhgiatridathuc
int i,n;
float a[30],x;
float pnx(void);
int main(void)
        {
                printf("Nhap bac cua da thuc: n = ");
                scanf("%d",&n);
                printf("Nhap cac he so:\n");
                for(i=0;i<=n;i++)
                        {
                                printf("a[%d] = ",i);
                                scanf("%f",&a[i]);
                        }
                printf("Nhap gia tri x = ");
                scanf("%f",&x);
                printf("P(%d,%.2f) = %.2f",n,x,pnx());
                return 0;
        }
float pnx(void)
        {
                float p=a[n];
                for(i=n;i>=1;i--)
                        p=p*x+a[i-1];
                return p;
        }
*/

/*KTLT_6_2_Tinhdiemthisinh
{
        struct thisinh
        {
                char hoten[30];
                float toan,ly,hoa,tong;
                char *loai[6];
        }ts;
        int i,n;
        FILE *fp;
        printf("Nhap so thi sinh n = ");scanf("%d",&n);
        fp=fopen("DIEM.DAT","wb");
        for(i=1;i<=n;i++)
                {
                        printf("Nhap thong tin cua thi sinh thu %d:\n",i);
                        printf("Ho ten: ");fpurge(stdin);gets(ts.hoten);
                        printf("Diem Toan: ");scanf("%f",&ts.toan);
                        printf("Diem Ly: ");scanf("%f",&ts.ly);
                        printf("Diem Hoa: ");scanf("%f",&ts.hoa);
                        ts.tong=ts.toan+ts.ly+ts.hoa;
                        if(ts.tong>19) *ts.loai="Do";
                        else *ts.loai="Truot";
                        fwrite(&ts,sizeof(ts),1,fp);
                }
        fclose(fp);
        printf("Danh sach thi sinh vua nhap:");
        fp=fopen("DIEM.DAT","rb");
        while(fread(&ts,sizeof(ts),1,fp)>0)
                printf("\n\t%s\t%.2f\t%.2f\t%.2f\t%.2f\t%s",ts.hoten,ts.toan,ts.ly,ts.hoa,ts.tong,*ts.loai);
        fclose(fp);
        return 0;
}
*/

/*KTLT_Chuyendoixauhex_sohe10
const char hex[16]="0123456789ABCDEF";
int main(void)
{
    char s[16];
    int i,j,n;
    long so=0;
    printf("Nhap xau s: ");
    scanf("%s",&s);
    n=strlen(s);
    for(i=0;i<n;i++)
        for(j=0;j<16;j++)
            if(s[i]==hex[j])
                {
                        so+=j*pow(16,n-i-1);
                        break;
                }
    printf("Xau %s o he 16 tuong ung voi so %ld o he 10",s,so);
    return 0;
}
*/

/*KTLT_ChuyenSohe10_xauHex
{
    char s[16],hex[16]="0123456789ABCDEF",xauhex[16];
    int i,j,n,sbc,du,dem;
    printf("Nhap so n: ");
    scanf("%d",&n);
    sbc=n;du=0;dem=0;
    while(sbc!=0)
            {
                    du=sbc%16;
                    for(j=0;j<=15;j++)
                            if(du==j)
                                    {s[dem]=hex[j];
                                    dem++;
                                    break;}
                    sbc/=16;
            }
    s[dem]='\0';
    for(i=0;i<strlen(s);i++)
            xauhex[i]=s[strlen(s)-i-1];
    xauhex[strlen(s)]='\0';
    printf("So %d o he 10 tuong ung voi xau %s o he 16",n,xauhex);
    return 0;
}
*/

/*KTLT_Contro_Hammaxmin
int maxday(int *a, int n);
int minday(int *a, int n);
int main(void)
{
  int *a,n,i;
  printf("Nhap so phan tu n = ");
  scanf("%d",&n);
  a = (int*)calloc(n,sizeof(int));
  for(i=0;i<n;i++)
      {
                printf("a[%d] = ",i);
                scanf("%d",&a[i]);
       }
  printf("max = %d",maxday(a,n));
  printf("\nmin = %d",minday(a,n));
  free(a);
  a=NULL;
  return 0;
}
int maxday(int *a, int n)
{
  int max,i;
  for(max=a[0],i=1;i<n;i++)
        if (a[i]>max)  max=a[i];
  return max;
}
int minday(int *a, int n)
{
  int min,i;
  for(min=a[0],i=1;i<n;i++)
        if (a[i]<min)  min=a[i];
  return min;
}
*/

/*KTLT_Contro_Tong_TBC_DemPTduong
int tong(int *a,int n);
float tbc(int *a,int n);
int demptduong(int *a,int n);
int main (void)
{
    int *a,i,n;
    printf("Nhap so phan tu n = ");
    scanf("%d",&n);
    a=(int*)calloc(n,sizeof(int));
    for(i=0;i<n;i++)
            {
                    printf("a[%d] = ",i);
                    scanf("%d",&a[i]);
            }
    printf("Tong cua day vua nhap la: %d",tong(a,n));
    printf("\nTrung binh cong cua day vua nhap la: %6.2f",tbc(a,n));
    printf("\nSo phan tu duong trong day vua nhap la: %d",demptduong(a,n));
    free(a);
    a=NULL;
    return 0;
}
int tong(int *a,int n)
{
    int i,s;
    for(s=0,i=0;i<n;i++)
            s+=a[i];
    return s;
}
float tbc(int *a,int n)
{
    return tong(a,n)/(float)n;
}
int demptduong(int *a,int n)
{
    int i,dem;
    for(dem=0,i=0;i<n;i++)
            if (a[i]>0) dem+=1;
    return dem;
}
*/

/*KTLT_Mangdong_Nguyento
int nguyento(int k);
int main(void)
{
    int *a,i,n;
    printf("Nhap so phan tu n = ");
    scanf("%d",&n);
    a=(int*)calloc(n,sizeof(int));
    for(i=0;i<n;i++)
        {
            printf("a[%d] = ",i);
            scanf("%d",&a[i]);
        }
    printf("Cac so nguyen to co trong day vua nhap:\n");
    for(i=0;i<n;i++)
            if(nguyento(a[i])) printf("%d   ",a[i]);
    free(a);
    a=NULL;
    return 0;
    }
    int nguyento(int k)
    {
    int i;
    if(k==1) return 0;
    for(i=2;i<k;i++)
            if(k%i==0) return 0;
    return 1;
}
*/

/* KTLT_TepQLNS
{
    struct nhanvien
    {
            char hoten[30],mapb[10],chucvu[20];
    }nv;
    int i,n;
    FILE *fp;
    printf("Nhap so luong nhan vien n = ");scanf("%d",&n);
    fp=fopen("Nhanvien.dat","wb");
    for(i=1;i<=n;i++)
    {
        printf("Nhap thong tin cua nhan vien thu %d:\n",i);
        printf("Ho ten: ");__fpurge(stdin);gets(nv.hoten);
        printf("Ma phong ban: ");__fpurge(stdin);gets(nv.mapb);
        printf("Chuc vu: ");__fpurge(stdin);gets(nv.chucvu);
        fwrite(&nv,sizeof(nv),1,fp);
    }
    fclose(fp);
    printf("Danh sach nhan vien thuoc phong Quan ly nhan su:");
    fp=fopen("nhanvien.dat","rb");
    while(fread(&nv,sizeof(nv),1,fp)>0)
        if(strcmp(nv.mapb,"QLNS")==0)
                printf("\n%-30s%-10s%-20s",nv.hoten,nv.mapb,nv.chucvu);
    fclose(fp);
    return 0;
}
*/