Advertisement
cd62131

9 x 9 matrix

Mar 1st, 2014
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main(void) {
  4.   int i, j;
  5.   char **matrix = (char **) malloc(9 * sizeof(char *));
  6.   const char **pmatrix = (const char **) malloc(9 * sizeof(char *));
  7.   for (i = 0; i < 9; i++) {
  8.     char *row = matrix[i] = (char *) malloc(9 * 3 + 1 + 1);
  9.     for (j = 0; j < 9; j++) {
  10.       sprintf(row, "%3d", (i + 1) * (j + 1)); row += 3;
  11.     }
  12.     sprintf(row, "\n");
  13.   }
  14.   for (i = 0; i < 9; i++) pmatrix[i] = matrix[i];
  15.   for (i = 0; i < 9; i++) printf("%s", pmatrix[i]);
  16.   return 0;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement