Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Nhap xuat mang bang file
- // Khai bao cac ham thu vien neu co
- #include<stdio.h>
- #include<conio.h>
- #include<string.h>
- #include<stdlib.h>
- #define SIZE 100
- #define input "nhap.txt"
- #define output "xuat.txt"
- void nhap(int A[][SIZE], int &m, int &n);
- void xuat(int A[SIZE][SIZE], int m, int n);
- void main()
- {
- int A[SIZE][SIZE],m,n;
- nhap(A,m,n);
- xuat(A,m,n);
- }
- // Ham nhap mang 2 chieu
- void nhap(int A[][SIZE], int &m, int &n)
- {
- FILE *fi;
- fi = fopen(input, "rt");
- if (fi == NULL)
- {
- printf("Khong tim thay file can doc!!!");
- exit(1);
- }
- fscanf(fi, "%d%d", &m, &n);
- for (int i = 0; i<m; i++)
- for (int j = 0; j<n; j++)
- fscanf(fi, "%d", &A[i][j]);
- fclose(fi);
- }
- // Ham xuat mang 2 chieu
- void xuat(int A[SIZE][SIZE], int m, int n)
- {
- FILE *fo;
- fo = fopen(output, "wt");
- if (fo == NULL)
- {
- printf("Khong ghi duoc file!!!");
- exit(1);
- }
- for (int i = 0; i<m; i++)
- for (int j = 0; j<n; j++)
- fprintf(fo, "%d ", A[i][j]);
- fclose(fo);
- }
- // bay gio chung ta vao noi chua code de tao file nhap.txt.
- // nhan Ctrl + F7 bien dich chuong trinh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement