Advertisement
Guest User

Untitled

a guest
May 27th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main ()
  5. {
  6.     int i, j;
  7.     FILE *mat;
  8.     mat = fopen("matriz1.txt", "w");
  9.     if (!mat)
  10.     {
  11.         printf("Erro ao abrir o arquivo!\n");
  12.         exit(0);
  13.     }
  14.     else
  15.     {
  16.         for (i = 0; i < 6; ++i)
  17.         {
  18.             for (j = 0; j <6; ++j)
  19.             {
  20.                 if ((i == 0 || i == 5) || (j == 0 || j == 5))
  21.                 {
  22.                     fprintf(mat, "1");
  23.                     if (j < 5) fprintf(mat, " ");
  24.                 }
  25.                 else if ((i == 1 || i == 4) || (j == 1 || j == 4))
  26.                 {
  27.                     fprintf(mat, "2 ");
  28.                 }
  29.                 else fprintf(mat, "3 ");
  30.             }
  31.             fprintf(mat, "\n");
  32.         }
  33.     }
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement