Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX_INPUT 1000
- int main()
- {
- FILE *fp;
- fp = fopen("input.txt", "r");
- if(fp == NULL) exit(EXIT_FAILURE);
- int imat;
- int matrice[MAX_INPUT];
- int num_col;
- int is_dim = 0;
- int num_counter = 0;
- while(!feof(fp) && num_counter < MAX_INPUT){
- fscanf(fp, "%d", &imat);
- printf("%d ", imat);
- if(is_dim == 0){
- num_col = imat;
- }
- else{
- matrice[num_counter] = imat;
- num_counter++;
- }
- is_dim++;
- }
- printf("\n");
- num_counter--;
- int num_rig = num_counter / num_col;
- printf("num_rig X num_col: %d x %d\n", num_rig, num_col);
- int i, j;
- for(i = 0; i < num_rig; i++){
- for(j = 0; j < num_col; j++){
- printf("%d ", matrice[i * num_col + j]);
- }
- printf("\n");
- }
- printf("Hello world!\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment