daily pastebin goal
20%
SHARE
TWEET

Untitled

a guest Mar 14th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct matrixTipus{
  5.     int **matrix;
  6.     int sorok;
  7.     int oszlop;
  8. } matrixTipus;
  9.  
  10. void lefoglalMatrix(matrixTipus * m)
  11. {
  12.     m->matrix = (int**)malloc(m->sorok*sizeof(int*));
  13.     int i,j;
  14.     for(i = 0; i<m->sorok; i++)
  15.     {
  16.         m->matrix[i]=(int*)malloc(m->oszlop*sizeof(int));
  17.         for(j=0; j<m->oszlop; j++)
  18.         {
  19.             m->matrix[i][j]=i+j;
  20.         }
  21.     }
  22. }
  23.  
  24. void lefoglal(int *** m, int sor, int oszlop)
  25. {
  26.     (*m) = (int**)malloc(sor*sizeof(int*));
  27.     int i,j;
  28.     for(i = 0; i<sor; i++)
  29.     {
  30.         (*m)[i]=(int*)malloc(oszlop*sizeof(int));
  31.         for(j=0; j<oszlop; j++)
  32.         {
  33.             (*m)[i][j]=i+j;
  34.         }
  35.     }
  36. }
  37.  
  38. void kiir(int ** m, int sorok, int oszlopok)
  39. {
  40.     int i ,j;
  41.     for(i=0; i<sorok; i++)
  42.     {
  43.         for(j=0; j<oszlopok; j++)
  44.         {
  45.             printf("%3d ",m[i][j]);
  46.         }
  47.         printf("\n");
  48.     }
  49.  
  50. }
  51.  
  52. void felszabadit(int *** m, int sorok)
  53. {
  54.     int i;
  55.     for(i=0; i<sorok; i++)
  56.     {
  57.         free( (*m)[i] );
  58.     }
  59.     free(*m);
  60.     *m = 0;
  61. }
  62.  
  63. int main(void) {
  64.  
  65.     /*int sorok = 5;
  66.     int oszlopok = 7;*/
  67.  
  68.     matrixTipus matrix;
  69.     matrix.sorok = 5;
  70.     matrix.oszlop = 7;
  71.  
  72.     /*int ** matrix = 0;
  73.     lefoglal(&matrix, sorok, oszlopok);
  74.     kiir(matrix,sorok,oszlopok);
  75.     felszabadit(&matrix, sorok);*/
  76.     return 0;
  77. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top