Pella86

MatriceCornice

Jul 17th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define MAX_INPUT 1000
  5.  
  6. int main()
  7. {
  8.  
  9.     FILE *fp;
  10.  
  11.     fp = fopen("input.txt", "r");
  12.     if(fp == NULL) exit(EXIT_FAILURE);
  13.  
  14.     int imat;
  15.  
  16.     int matrice[MAX_INPUT];
  17.     int num_col;
  18.     int is_dim = 0;
  19.     int num_counter = 0;
  20.  
  21.     while(!feof(fp) && num_counter < MAX_INPUT){
  22.         fscanf(fp, "%d", &imat);
  23.         printf("%d ", imat);
  24.         if(is_dim == 0){
  25.             num_col = imat;
  26.         }
  27.         else{
  28.             matrice[num_counter] = imat;
  29.             num_counter++;
  30.         }
  31.  
  32.         is_dim++;
  33.     }
  34.     printf("\n");
  35.  
  36.     num_counter--;
  37.  
  38.     int num_rig = num_counter / num_col;
  39.     printf("num_rig X num_col: %d x %d\n", num_rig, num_col);
  40.  
  41.     int i, j;
  42.  
  43.     for(i = 0; i < num_rig; i++){
  44.         for(j = 0; j < num_col; j++){
  45.             printf("%d ", matrice[i * num_col + j]);
  46.         }
  47.         printf("\n");
  48.     }
  49.  
  50.     printf("Hello world!\n");
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment