Matrix in C language

freez -  
R4f Posted messages 441 Status Member -
Hello everyone !!
I need to fill a matrix in a somewhat delicate way:
I have the number of columns and rows, but I need to fill it so that each column encodes its number in binary!!!
Basically, the matrix will contain only 1s and 0s...
If the number of columns = 5
and the number of rows = 3
the matrix would look like this:

1 0 1 0 1
0 1 1 0 0
0 0 0 1 1

HELP ME PLEASE !!

I’m waiting for you!!!
Configuration: Windows XP Firefox 2.0.0.9

3 answers

  1. R4f Posted messages 441 Status Member 62
     
    ```c
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    main() {
    long *matrice[3];
    int i;
    for(i=0; i<3; i++) {
    int taille = sizeof(long[5]);
    matrice[i] = (long *)malloc(taille);
    int j;
    for(j=0; j<5; j++) {
    matrice[i][j] = ((j+1) & (int)pow(2,i)) >> i;
    }
    }
    for(i=0; i<3; i++) {
    int j;
    for(j=0; j<5; j++) {
    printf("%d ", matrice[i][j]);
    }
    printf("\n");
    }
    for(i=0; i<3; i++) {
    free(matrice[i]);
    }
    }
    ```</math.h></stdlib.h></stdio.h>
    1