0% found this document useful (0 votes)
11 views3 pages

10.1 LTCB

Uploaded by

trongdth216218
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

10.1 LTCB

Uploaded by

trongdth216218
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <stdio.

h>

#define MAX 100

//bai 10.1

int main()

int arr[MAX];

int n,i;

do{

printf("Nhap vao so phan tu cua danh sach: ");

scanf("%d",&n);

while(n<=0);

printf("Nhap gia tri danh sach: \n");

for(i=0; i<n; i++)

printf("Nhap phan tu thu %d: ",i+1);

scanf("%d",&arr[i]);

FILE *fo =fopen("dulieu.txt", "wt");

if(fo!=NULL)

for(i=0;i<n;i++)

printf("Ghi phan tu thu arr[%d] =%d vao file\n",i+1,arr[i]);

fprintf(fo,"%d",arr[i]);

fprintf(fo,"\n");

int tong=0;

for(i=0; i<n; i++)


{

tong += arr[i];

if(fo!=NULL)

printf("Ghi tong =%d vao file\n",tong);

fprintf(fo,"%d",tong);

fprintf(fo,"\n");

fclose(fo);

FILE *fi =fopen("dulieu.txt","rt");

printf("Doc du lieu tu tap tin:\n");

if(fi!=NULL)

int tmp;

while(!feof(fi))

fscanf(fi,"%d",&tmp);

printf("%d\t",tmp);

printf("\n");

fclose(fi);

for(int i=0; i<n; i++)

for(int j=i+1; j<n; j++)

if(arr[i]>arr[j])

int tmp =arr[i];

arr[i] = arr[j];

arr[j] = tmp;

}
fo = fopen("dulieu.txt","at");

if(fo!=NULL)

for(i=0; i<n; i++)

printf("Ghi phan tu thu arr[%d]=%d vao file\n",i+1,arr[i]);

fprintf(fo,"%d",arr[i]);

fprintf(fo,"\n");

fclose(fo);

return 0;

You might also like